ChecksumBlobTest.cpp 2.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/*!
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2019 CERN
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "common/checksum/ChecksumBlob.hpp"
#include <gtest/gtest.h>

namespace unitTests {

class cta_ChecksumBlobTest : public ::testing::Test {
protected:
  virtual void SetUp() {
  }

  virtual void TearDown() {
  }
};

TEST_F(cta_ChecksumBlobTest, default_constructor) {
34
  using namespace cta::checksum;
35
36
37
38
39
40

  const ChecksumBlob checksumBlob;

  ASSERT_EQ(checksumBlob.length(), 0);
}

41
42
43
44
45
46
47
48
TEST_F(cta_ChecksumBlobTest, checksum_types) {
  using namespace cta::checksum;

  ChecksumBlob checksumBlob;
  checksumBlob.insert(NONE, "");
  checksumBlob.insert(ADLER32, "12\0004");
}

49
TEST_F(cta_ChecksumBlobTest, adler32) {
50
  using namespace cta::checksum;
51
52

  ChecksumBlob checksumBlob;
53
  checksumBlob.insert(ADLER32, 0x0A141E28);
54
55
  ASSERT_EQ(checksumBlob.length(), 1);

56
  std::string bytearray = checksumBlob.at(ADLER32);
57
58
59
60
61
62
63
64

  ASSERT_EQ(4, bytearray.length());
  ASSERT_EQ(static_cast<uint8_t>(10), bytearray[0]);
  ASSERT_EQ(static_cast<uint8_t>(20), bytearray[1]);
  ASSERT_EQ(static_cast<uint8_t>(30), bytearray[2]);
  ASSERT_EQ(static_cast<uint8_t>(40), bytearray[3]);
}

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
TEST_F(cta_ChecksumBlobTest, invalid_checksums) {
  using namespace cta::checksum;

  ChecksumBlob checksumBlob;
  checksumBlob.insert(NONE, "none");
  checksumBlob.insert(MD5, 0x0A141E28);
}

TEST_F(cta_ChecksumBlobTest, serialize_deserialize) {
  using namespace cta::checksum;

  ChecksumBlob checksumBlob1;
  auto bytearray = checksumBlob1.serialize();

  ChecksumBlob checksumBlob2;
  checksumBlob2.deserialize(bytearray);
  ASSERT_EQ(checksumBlob1, checksumBlob2);
}

84
} // namespace unitTests