ArchiveFileTest.cpp 3.82 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
 * The CERN Tape Archive (CTA) project
 * Copyright (C) 2015  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/dataStructures/ArchiveFile.hpp"

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

namespace unitTests {

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

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
45
  archiveFile1.diskFileId = "EOS_file_ID";
46
  archiveFile1.fileSize = 1;
47
  archiveFile1.checksumBlob.insert(cta::Checksum::CHECKSUMTYPE_ADLER32, "1234");
48
49
50
  archiveFile1.storageClass = "storage_class";

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

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

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

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

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

  ArchiveFile archiveFile2;

  archiveFile2 = archiveFile1;

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

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

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

  {
93
94
    auto copyNbToTapeFileItor = std::find_if(archiveFile2.tapeFiles.begin(), archiveFile2.tapeFiles.end(),
        [](TapeFile &tf){ return tf.copyNb == 1; });
95
    ASSERT_TRUE(copyNbToTapeFileItor != archiveFile2.tapeFiles.end());
96
97
98
99
    ASSERT_EQ(tapeFile1.vid, copyNbToTapeFileItor->vid);
    ASSERT_EQ(tapeFile1.fSeq, copyNbToTapeFileItor->fSeq);
    ASSERT_EQ(tapeFile1.blockId, copyNbToTapeFileItor->blockId);
    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
109
    ASSERT_EQ(tapeFile2.vid, copyNbToTapeFileItor->vid);
    ASSERT_EQ(tapeFile2.fSeq, copyNbToTapeFileItor->fSeq);
    ASSERT_EQ(tapeFile2.blockId, copyNbToTapeFileItor->blockId);
    ASSERT_EQ(tapeFile2.copyNb, copyNbToTapeFileItor->copyNb);
110
111
112
113
  }
}

} // namespace unitTests