1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2020-2020 Bareos GmbH & Co. KG
5 
6    This program is Free Software; you can redistribute it and/or
7    modify it under the terms of version three of the GNU Affero General Public
8    License as published by the Free Software Foundation and included
9    in the file LICENSE.
10 
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14    Affero General Public License for more details.
15 
16    You should have received a copy of the GNU Affero General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.
20 */
21 
22 #if defined(HAVE_MINGW)
23 #  include "include/bareos.h"
24 #  include "gtest/gtest.h"
25 #else
26 #  include "gtest/gtest.h"
27 #  include "include/bareos.h"
28 #endif
29 
30 #include <iostream>
31 #include "cats/cats.h"
32 
TEST(db_list_ctx,ConstructorsTest)33 TEST(db_list_ctx, ConstructorsTest)
34 {
35   db_list_ctx list1;
36   EXPECT_TRUE(list1.empty());
37 
38   list1.add("Test123");
39   EXPECT_EQ(0, list1.at(0).compare(std::string("Test123")));
40 
41   BStringList list2(list1);
42   EXPECT_EQ(1, list2.size());
43   EXPECT_EQ(0, list2.front().compare(std::string("Test123")));
44 }
45 
TEST(db_list_ctx,AddJobId)46 TEST(db_list_ctx, AddJobId)
47 {
48   db_list_ctx list1;
49   EXPECT_TRUE(list1.empty());
50 
51   JobId_t jobid = 3;
52 
53   list1.add("Test1");
54   list1.add("Test2");
55   list1.add(jobid);
56 
57   EXPECT_EQ(3, list1.size());
58   EXPECT_EQ(0, list1.at(2).compare(std::to_string(jobid)));
59 }
60 
TEST(db_list_ctx,AddList)61 TEST(db_list_ctx, AddList)
62 {
63   db_list_ctx list1;
64   EXPECT_TRUE(list1.empty());
65 
66   JobId_t jobid1 = 13;
67 
68   list1.add("Test11");
69   list1.add("Test12");
70   list1.add(jobid1);
71 
72   EXPECT_EQ(3, list1.size());
73 
74   db_list_ctx list2;
75 
76   JobId_t jobid2 = 23;
77 
78   list2.add("Test21");
79   list2.add("Test22");
80   list2.add(jobid2);
81 
82   list1.add(list2);
83 
84   EXPECT_EQ(3, list2.size());
85 
86   EXPECT_EQ(6, list1.size());
87   EXPECT_EQ(0, list1.at(1).compare(std::string("Test12")));
88   EXPECT_EQ(0, list1.at(4).compare(std::string("Test22")));
89 }
90 
TEST(db_list_ctx,list)91 TEST(db_list_ctx, list)
92 {
93   db_list_ctx list1;
94 
95   list1.add(11);
96   list1.add(12);
97   list1.add(13);
98 
99   EXPECT_EQ(3, list1.size());
100   EXPECT_EQ(0, list1.GetAsString().compare(std::string("11,12,13")));
101   // std::cerr << "list: " << list1.list() << "\n";
102   EXPECT_TRUE(bstrcmp(list1.GetAsString().c_str(), "11,12,13"));
103   EXPECT_STREQ(list1.GetAsString().c_str(), "11,12,13");
104 }
105 
TEST(db_list_ctx,GetFrontAsInteger)106 TEST(db_list_ctx, GetFrontAsInteger)
107 {
108   db_list_ctx nb;
109 
110   EXPECT_EQ(0, nb.GetFrontAsInteger());
111 
112   nb.add(11);
113   EXPECT_EQ(11, nb.GetFrontAsInteger());
114 
115   nb.add(12);
116   EXPECT_EQ(11, nb.GetFrontAsInteger());
117 }
118