ArchiveFileTest.cpp 3.9 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
47
48
49
50
51
  archiveFile1.fileSize = 1;
  archiveFile1.checksumType = "checksum_type";
  archiveFile1.checksumValue = "cheskum_value";
  archiveFile1.storageClass = "storage_class";

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

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

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

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

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

  ArchiveFile archiveFile2;

  archiveFile2 = archiveFile1;

  ASSERT_EQ(archiveFile1.archiveFileID, archiveFile2.archiveFileID);
81
  ASSERT_EQ(archiveFile1.diskFileId, archiveFile2.diskFileId);
82
83
84
85
86
87
  ASSERT_EQ(archiveFile1.fileSize, archiveFile2.fileSize);
  ASSERT_EQ(archiveFile1.checksumType, archiveFile2.checksumType);
  ASSERT_EQ(archiveFile1.checksumValue, archiveFile2.checksumValue);
  ASSERT_EQ(archiveFile1.storageClass, archiveFile2.storageClass);

  ASSERT_EQ(archiveFile1.diskInstance, archiveFile2.diskInstance);
88
  ASSERT_EQ(archiveFile1.diskFileInfo.path, archiveFile2.diskFileInfo.path);
89
90
  ASSERT_EQ(archiveFile1.diskFileInfo.owner_uid, archiveFile2.diskFileInfo.owner_uid);
  ASSERT_EQ(archiveFile1.diskFileInfo.gid, archiveFile2.diskFileInfo.gid);
91

92
  ASSERT_EQ(2, archiveFile2.tapeFiles.size());
93
94

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

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

} // namespace unitTests