Skip to content

Commit

Permalink
ported tests partly to gtest
Browse files Browse the repository at this point in the history
  • Loading branch information
pstorz committed Dec 20, 2017
1 parent 0e8fd13 commit 443ce96
Show file tree
Hide file tree
Showing 15 changed files with 125 additions and 359 deletions.
43 changes: 0 additions & 43 deletions src/findlib/unittests/test_findlib.cc

This file was deleted.

2 changes: 1 addition & 1 deletion src/lib/rblist.cc
Expand Up @@ -23,7 +23,7 @@
*
* rblist is a binary tree with the links being in the data item.
*
* Developped in part from ideas obtained from several online University courses.
* Developed in part from ideas obtained from several online University courses.
*
* Kern Sibbald, November MMV
*/
Expand Down
37 changes: 20 additions & 17 deletions src/lib/unittests/CMakeLists.txt
Expand Up @@ -20,22 +20,21 @@
include_directories(.. ../.. ../../include/)

set (TEST_SRC
alist_test.cc
base64_test.cc
bsnprintf_test.cc
devlock_test.cc
dlist_test.cc
edit_test.cc
htable_test.cc
#ini_test.cc
junction_test.cc
passphrase_test.cc
rblist_test.cc
rwlock_test.cc
scan_test.cc
sellist_test.cc
test_lib.cc
alist_test.cc
dlist_test.cc
base64_test.cc
bsnprintf_test.cc
# devlock_test.cc
edit_test.cc
htable_test.cc
junction_test.cc
passphrase_test.cc
scan_test.cc
# rwlock_test.cc
# sellist_test.cc
#tree_test.cc
#rblist_test.cc
#ini_test.cc
)


Expand All @@ -48,13 +47,17 @@ target_link_libraries(test_lib
bareos
${JANSSON_LIBRARIES}
${CMOCKA_LIBRARIES}
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

add_test(NAME test_lib
COMMAND test_lib
)
set_property(TEST test_lib
PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/lib")

set_property(TEST test_lib
PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/src/lib"
PROPERTY ENVIRONMENT "GTEST_COLOR=yes"
)

add_dependencies(check test_lib)
35 changes: 14 additions & 21 deletions src/lib/unittests/alist_test.cc
Expand Up @@ -26,14 +26,8 @@
*
* Philipp Storz, April 2015
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>

extern "C" {
#include <cmocka.h>
}

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

struct FILESET {
Expand Down Expand Up @@ -64,7 +58,7 @@ void alist_fill(alist *list, int max)
/*
* verify that max elements have been added
*/
assert_int_equal(list->size(), start + max);
EXPECT_EQ(list->size(), start + max);
}

/*
Expand All @@ -82,18 +76,18 @@ void test_foreach_alist(alist *list)

foreach_alist(str, list) {
sprintf(buf, "%d", i);
assert_string_equal(str, buf);
EXPECT_STREQ(str, buf);
i++;
}

foreach_alist_index(i, str, list) {
sprintf(buf, "%d", i);
assert_string_equal(str, buf);
EXPECT_STREQ(str, buf);
}

foreach_alist_rindex(i, str, list) {
sprintf(buf, "%d", i);
assert_string_equal(str, buf);
EXPECT_STREQ(str, buf);
}
}

Expand All @@ -110,7 +104,7 @@ void test_alist_init_destroy()

alist_fill(&(fileset->mylist), 20);
for (int i=0; i< fileset->mylist.size(); i++) {
assert_int_equal(i, atoi((char *)fileset->mylist[i]));
EXPECT_EQ(i, atoi((char *)fileset->mylist[i]));
}
fileset->mylist.destroy();
free(fileset);
Expand All @@ -123,14 +117,14 @@ void test_alist_dynamic() {
char *buf;

// NULL->size() will segfault
//assert_int_equal(list->size(), 0);
//EXPECT_EQ(list->size(), 0);

// does foreach work for NULL?
test_foreach_alist(list);

// create empty list, which is prepared for a number of entires
list = New(alist(10));
assert_int_equal(list->size(), 0);
EXPECT_EQ(list->size(), 0);

// does foreach work for empty lists?
test_foreach_alist(list);
Expand All @@ -140,21 +134,21 @@ void test_alist_dynamic() {
test_foreach_alist(list);

// verify and remove the latest entries
assert_int_equal(list->size(), 20);
EXPECT_EQ(list->size(), 20);
buf = (char *)list->pop();
assert_string_equal(buf, "19");
EXPECT_STREQ(buf, "19");
free(buf);

assert_int_equal(list->size(), 19);
EXPECT_EQ(list->size(), 19);
buf = (char *)list->pop();
assert_string_equal(buf, "18");
EXPECT_STREQ(buf, "18");
free(buf);

// added more entires
alist_fill(list, 20);
test_foreach_alist(list);

assert_int_equal(list->size(), 38);
EXPECT_EQ(list->size(), 38);

delete(list);
}
Expand All @@ -163,9 +157,8 @@ void test_alist_dynamic() {
/*
* main entry point
*/
void test_alist(void **state) {
(void) state; /* unused */

TEST(alist, alist) {
test_alist_init_destroy();
test_alist_dynamic();

Expand Down
81 changes: 14 additions & 67 deletions src/lib/unittests/base64_test.cc
Expand Up @@ -26,14 +26,11 @@
*
* Philipp Storz, April 2015
*/
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>

extern "C" {
#include <cmocka.h>
}



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

#ifdef HAVE_WIN32
Expand All @@ -51,14 +48,12 @@ static int errfunc(const char *epath, int eernoo)
}


void test_base64(void **state) {
(void) state; /* unused */


/*
* Test the base64 routines by encoding and decoding
* lstat() packets.
*/
TEST(base64, base64) {
/*
* Test the base64 routines by encoding and decoding
* lstat() packets.
*/

char where[500];
int i;
Expand All @@ -71,7 +66,7 @@ void test_base64(void **state) {
time_t t = 1028712799;


fname = BINARYNAME;
fname = (char*)BINARYNAME;
base64_init();
if (lstat(fname, &statp) < 0) {
berrno be;
Expand Down Expand Up @@ -107,7 +102,8 @@ void test_base64(void **state) {

decode_stat(where, &statn, sizeof(statn), &j);

assert_false(statp.st_dev != statn.st_dev ||
EXPECT_FALSE(
statp.st_dev != statn.st_dev ||
statp.st_ino != statn.st_ino ||
statp.st_mode != statn.st_mode ||
statp.st_nlink != statn.st_nlink ||
Expand All @@ -119,56 +115,7 @@ void test_base64(void **state) {
statp.st_blocks != statn.st_blocks ||
statp.st_atime != statn.st_atime ||
statp.st_mtime != statn.st_mtime ||
statp.st_ctime != statn.st_ctime);

/*
{ printf("%s: %s\n", fname, where);
encode_stat(where, &statn, sizeof(statn), 0, 0);
printf("%s: %s\n", fname, where);
printf("NOT EQAL\n");
}
*/


//printf("%d files examined\n", i);

to_base64(UINT32_MAX, where);
//printf("UINT32_MAX=%s\n", where);











int xx = 0;
int len;
char buf[100];
char junk[100];
// int i;

#ifdef xxxx
for (i=0; i < 1000; i++) {
bin_to_base64(buf, sizeof(buf), (char *)&xx, 4, true);
printf("xx=%s\n", buf);
xx++;
}
#endif
junk[0] = 0xFF;
for (i=1; i<100; i++) {
junk[i] = junk[i-1]-1;
}
len = bin_to_base64(buf, sizeof(buf), junk, 16, true);
//printf("len=%d junk=%s\n", len, buf);

strcpy(junk, "This is a sample string");
len = bin_to_base64(buf, sizeof(buf), junk, strlen(junk), true);
buf[len] = 0;
base64_to_bin(junk, sizeof(junk), buf, len);
//printf("buf=<%s>\n", junk);

statp.st_ctime != statn.st_ctime
);
to_base64(UINT32_MAX, where);
}

0 comments on commit 443ce96

Please sign in to comment.