Skip to content

Commit

Permalink
tests: added test for fileindex list
Browse files Browse the repository at this point in the history
  • Loading branch information
franku authored and arogge committed Jun 28, 2019
1 parent 56c8810 commit fe746ca
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/dird/bsr.h
Expand Up @@ -35,6 +35,8 @@

#include "dird/ua.h"

struct VolumeParameters;

namespace directordaemon {

/**
Expand Down
22 changes: 22 additions & 0 deletions core/src/tests/CMakeLists.txt
Expand Up @@ -259,3 +259,25 @@ target_link_libraries(test_setdebug

gtest_discover_tests(test_setdebug TEST_PREFIX gtest:)

####### test_fileindex_list #####################################
add_executable(test_fileindex_list test_fileindex_list.cc)

target_link_libraries(test_fileindex_list
dird_objects
bareos
bareosfind
bareoscats
bareossql
$<$<BOOL:HAVE_PAM>:${PAM_LIBRARIES}>
${LMDB_LIBS}
${NDMP_LIBS}
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

add_test(NAME test_fileindex_list
COMMAND test_fileindex_list
)

gtest_discover_tests(test_fileindex_list TEST_PREFIX gtest:)

76 changes: 76 additions & 0 deletions core/src/tests/test_fileindex_list.cc
@@ -0,0 +1,76 @@
/*
BAREOS® - Backup Archiving REcovery Open Sourced
Copyright (C) 2019-2019 Bareos GmbH & Co. KG
This program is Free Software; you can redistribute it and/or
modify it under the terms of version three of the GNU Affero General Public
License as published by the Free Software Foundation and included
in the file LICENSE.
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
Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/

#include "gtest/gtest.h"
#include "include/bareos.h"

#include "dird/bsr.h"

#include <chrono>
#include <iostream>

using namespace std::chrono;
using namespace directordaemon;
using namespace std;

namespace directordaemon {
bool DoReloadConfig() { return false; }
} // namespace directordaemon

enum
{
kJobId_1 = 1,
kJobId_2 = 2
};

TEST(fileindex_list, add_filendexes)
{
RestoreBootstrapRecord bsr;
AddFindex(&bsr, kJobId_1, 1);
ASSERT_NE(bsr.fi, nullptr);
EXPECT_EQ(bsr.fi->findex, 1);
EXPECT_EQ(bsr.fi->findex2, 1);
EXPECT_EQ(bsr.JobId, kJobId_1);

AddFindex(&bsr, kJobId_2, 2);
ASSERT_NE(bsr.next, nullptr);
EXPECT_EQ(bsr.next->JobId, kJobId_2);
ASSERT_NE(bsr.next->fi, nullptr);
EXPECT_EQ(bsr.next->fi->findex, 2);
EXPECT_EQ(bsr.next->fi->findex2, 2);

AddFindex(&bsr, kJobId_1, 3);
EXPECT_EQ(bsr.JobId, kJobId_1);
ASSERT_NE(bsr.fi, nullptr);
ASSERT_NE(bsr.fi->next, nullptr);
EXPECT_EQ(bsr.fi->next->findex, 3);
EXPECT_EQ(bsr.fi->next->findex2, 3);

AddFindex(&bsr, kJobId_2, 4);
ASSERT_NE(bsr.next, nullptr);
EXPECT_EQ(bsr.next->JobId, kJobId_2);
ASSERT_NE(bsr.next->fi, nullptr);
EXPECT_EQ(bsr.next->fi->findex, 2);
EXPECT_EQ(bsr.next->fi->findex2, 2);
ASSERT_NE(bsr.next->fi->next, nullptr);
EXPECT_EQ(bsr.next->fi->next->findex, 4);
EXPECT_EQ(bsr.next->fi->next->findex2, 4);
}

0 comments on commit fe746ca

Please sign in to comment.