ArchiveFileTest.cpp 4.12 KB
Newer Older
1
/*
2
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2015-2021 CERN
4
5
6
7
 * @license        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.
8
 *
9
10
11
12
 *                 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.
13
 *
14
15
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18
19
20
 */

#include "common/dataStructures/ArchiveFile.hpp"

#include <gtest/gtest.h>
21
#include <algorithm>
22
23
24

namespace unitTests {

25
26
27
const uint32_t RECOVERY_OWNER_UID = 9751;
const uint32_t RECOVERY_GID       = 9752;

28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class cta_common_dataStructures_ArchiveFileTest : public ::testing::Test {
protected:

  virtual void SetUp() {
  }

  virtual void TearDown() {
  }
};

TEST_F(cta_common_dataStructures_ArchiveFileTest, copy_constructor) {
  using namespace cta::common::dataStructures;

  ArchiveFile archiveFile1;

  archiveFile1.archiveFileID = 1234;
44
  archiveFile1.diskFileId = "EOS_file_ID";
45
  archiveFile1.fileSize = 1;
46
  archiveFile1.checksumBlob.insert(cta::checksum::ADLER32, "1234");
47
48
49
  archiveFile1.storageClass = "storage_class";

  archiveFile1.diskInstance = "recovery_instance";
50
  archiveFile1.diskFileInfo.path = "recovery_path";
51
52
  archiveFile1.diskFileInfo.owner_uid = RECOVERY_OWNER_UID;
  archiveFile1.diskFileInfo.gid = RECOVERY_GID;
53
54
55
56
57

  TapeFile tapeFile1;
  tapeFile1.vid = "VID1";
  tapeFile1.fSeq = 5678;
  tapeFile1.blockId = 9012;
58
  tapeFile1.fileSize = 5;
59
60
  tapeFile1.copyNb = 1;

61
  archiveFile1.tapeFiles.push_back(tapeFile1);
62
  ASSERT_EQ(1, archiveFile1.tapeFiles.size());
63
64
65
66
67

  TapeFile tapeFile2;
  tapeFile2.vid = "VID2";
  tapeFile2.fSeq = 3456;
  tapeFile2.blockId = 7890;
68
  tapeFile2.fileSize = 6;
69
70
  tapeFile2.copyNb = 2;

71
  archiveFile1.tapeFiles.push_back(tapeFile2);
72
  ASSERT_EQ(2, archiveFile1.tapeFiles.size());
73
74
75
76
77
78

  ArchiveFile archiveFile2;

  archiveFile2 = archiveFile1;

  ASSERT_EQ(archiveFile1.archiveFileID, archiveFile2.archiveFileID);
79
  ASSERT_EQ(archiveFile1.diskFileId, archiveFile2.diskFileId);
80
  ASSERT_EQ(archiveFile1.fileSize, archiveFile2.fileSize);
81
  ASSERT_EQ(archiveFile1.checksumBlob, archiveFile2.checksumBlob);
82
83
84
  ASSERT_EQ(archiveFile1.storageClass, archiveFile2.storageClass);

  ASSERT_EQ(archiveFile1.diskInstance, archiveFile2.diskInstance);
85
  ASSERT_EQ(archiveFile1.diskFileInfo.path, archiveFile2.diskFileInfo.path);
86
87
  ASSERT_EQ(archiveFile1.diskFileInfo.owner_uid, archiveFile2.diskFileInfo.owner_uid);
  ASSERT_EQ(archiveFile1.diskFileInfo.gid, archiveFile2.diskFileInfo.gid);
88

89
  ASSERT_EQ(2, archiveFile2.tapeFiles.size());
90
91

  {
92
93
    auto copyNbToTapeFileItor = std::find_if(archiveFile2.tapeFiles.begin(), archiveFile2.tapeFiles.end(),
        [](TapeFile &tf){ return tf.copyNb == 1; });
94
    ASSERT_TRUE(copyNbToTapeFileItor != archiveFile2.tapeFiles.end());
95
96
97
    ASSERT_EQ(tapeFile1.vid, copyNbToTapeFileItor->vid);
    ASSERT_EQ(tapeFile1.fSeq, copyNbToTapeFileItor->fSeq);
    ASSERT_EQ(tapeFile1.blockId, copyNbToTapeFileItor->blockId);
98
    ASSERT_EQ(tapeFile1.fileSize, copyNbToTapeFileItor->fileSize);
99
    ASSERT_EQ(tapeFile1.copyNb, copyNbToTapeFileItor->copyNb);
100
101
102
  }

  {
103
104
    auto copyNbToTapeFileItor = std::find_if(archiveFile2.tapeFiles.begin(), archiveFile2.tapeFiles.end(),
        [](TapeFile &tf){ return tf.copyNb == 2; });
105
    ASSERT_TRUE(copyNbToTapeFileItor != archiveFile2.tapeFiles.end());
106
107
108
    ASSERT_EQ(tapeFile2.vid, copyNbToTapeFileItor->vid);
    ASSERT_EQ(tapeFile2.fSeq, copyNbToTapeFileItor->fSeq);
    ASSERT_EQ(tapeFile2.blockId, copyNbToTapeFileItor->blockId);
109
    ASSERT_EQ(tapeFile2.fileSize, copyNbToTapeFileItor->fileSize);
110
    ASSERT_EQ(tapeFile2.copyNb, copyNbToTapeFileItor->copyNb);
111
112
113
114
  }
}

} // namespace unitTests