summaryrefslogtreecommitdiff
path: root/test/libapt
diff options
context:
space:
mode:
Diffstat (limited to 'test/libapt')
-rw-r--r--test/libapt/CMakeLists.txt22
-rw-r--r--test/libapt/fileutl_test.cc2
-rw-r--r--test/libapt/hashsums_test.cc14
-rw-r--r--test/libapt/makefile84
4 files changed, 30 insertions, 92 deletions
diff --git a/test/libapt/CMakeLists.txt b/test/libapt/CMakeLists.txt
new file mode 100644
index 000000000..7f9990526
--- /dev/null
+++ b/test/libapt/CMakeLists.txt
@@ -0,0 +1,22 @@
+include(ExternalProject)
+
+set(GTEST_ROOT "/usr/src/gtest" CACHE FILEPATH "Path to GTest CMake project")
+
+message(STATUS "Found GTest at ${GTEST_ROOT}")
+
+if (EXISTS ${GTEST_ROOT})
+
+ExternalProject_Add(gtest PREFIX ./gtest
+ SOURCE_DIR ${GTEST_ROOT}
+ INSTALL_COMMAND true)
+
+link_directories(${CMAKE_CURRENT_BINARY_DIR}/gtest/src/gtest-build)
+FILE(GLOB files gtest_runner.cc *-helpers.cc *_test.cc)
+add_executable(libapt_test ${files})
+target_link_libraries(libapt_test -lgtest ${CMAKE_THREAD_LIBS_INIT} apt-private apt-inst)
+add_dependencies(libapt_test gtest)
+add_test(NAME AptTests
+ COMMAND libapt_test
+ WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
+
+endif()
diff --git a/test/libapt/fileutl_test.cc b/test/libapt/fileutl_test.cc
index 0a299b51a..67bd850a1 100644
--- a/test/libapt/fileutl_test.cc
+++ b/test/libapt/fileutl_test.cc
@@ -216,7 +216,7 @@ TEST(FileUtlTest, Glob)
{
std::vector<std::string> files;
// normal match
- files = Glob("*akefile");
+ files = Glob("*MakeLists.txt");
EXPECT_EQ(1, files.size());
// not there
diff --git a/test/libapt/hashsums_test.cc b/test/libapt/hashsums_test.cc
index 705c0297d..fb9a25643 100644
--- a/test/libapt/hashsums_test.cc
+++ b/test/libapt/hashsums_test.cc
@@ -119,7 +119,7 @@ static void getSummationString(char const * const type, std::string &sum)
FileFd fd;
ASSERT_TRUE(fd.Open(tempfile, FileFd::WriteOnly | FileFd::Empty, compress));
ASSERT_TRUE(fd.IsOpen());
- FileFd input(__FILE__, FileFd::ReadOnly);
+ FileFd input("/etc/os-release", FileFd::ReadOnly);
ASSERT_TRUE(input.IsOpen());
ASSERT_NE(0, input.FileSize());
ASSERT_TRUE(CopyFile(input, fd));
@@ -161,7 +161,7 @@ TEST(HashSumsTest, FileBased)
SHA512SumValue sha512(summation);
EXPECT_EQ(sha512.Value(), summation);
- FileFd fd(__FILE__, FileFd::ReadOnly);
+ FileFd fd("/etc/os-release", FileFd::ReadOnly);
EXPECT_TRUE(fd.IsOpen());
std::string FileSize;
strprintf(FileSize, "%llu", fd.FileSize());
@@ -243,18 +243,18 @@ TEST(HashSumsTest, FileBased)
fd.Close();
HashString sha2file("SHA512", sha512.Value());
- EXPECT_TRUE(sha2file.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2file.VerifyFile("/etc/os-release"));
HashString sha2wrong("SHA512", "00000000000");
- EXPECT_FALSE(sha2wrong.VerifyFile(__FILE__));
+ EXPECT_FALSE(sha2wrong.VerifyFile("/etc/os-release"));
EXPECT_EQ(sha2file, sha2file);
EXPECT_TRUE(sha2file == sha2file);
EXPECT_NE(sha2file, sha2wrong);
EXPECT_TRUE(sha2file != sha2wrong);
HashString sha2big("SHA256", sha256.Value());
- EXPECT_TRUE(sha2big.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2big.VerifyFile("/etc/os-release"));
HashString sha2small("sha256:" + sha256.Value());
- EXPECT_TRUE(sha2small.VerifyFile(__FILE__));
+ EXPECT_TRUE(sha2small.VerifyFile("/etc/os-release"));
EXPECT_EQ(sha2big, sha2small);
EXPECT_TRUE(sha2big == sha2small);
EXPECT_FALSE(sha2big != sha2small);
@@ -283,7 +283,7 @@ TEST(HashSumsTest, FileBased)
EXPECT_EQ(2, hashes.size());
EXPECT_FALSE(hashes.push_back(sha2wrong));
EXPECT_EQ(2, hashes.size());
- EXPECT_TRUE(hashes.VerifyFile(__FILE__));
+ EXPECT_TRUE(hashes.VerifyFile("/etc/os-release"));
EXPECT_EQ(similar, hashes);
EXPECT_TRUE(similar == hashes);
diff --git a/test/libapt/makefile b/test/libapt/makefile
deleted file mode 100644
index 5ff9cf68a..000000000
--- a/test/libapt/makefile
+++ /dev/null
@@ -1,84 +0,0 @@
-# -*- make -*-
-BASE=../..
-SUBDIR=test/libapt
-BASENAME=_libapt_test
-APT_DOMAIN=none
-
-# Bring in the default rules
-include ../../buildlib/defaults.mak
-
-.PHONY: test
-ifeq (file-okay,$(shell $(CC) -I $(BASE)/build/include -M gtest_runner.cc >/dev/null 2>&1 && echo 'file-okay'))
-test: $(BIN)/gtest$(BASENAME)
- MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=$(LIB) $(BIN)/gtest$(BASENAME)
-
-$(BIN)/gtest$(BASENAME): $(LIB)/gtest.a
-
-PROGRAM = gtest${BASENAME}
-SLIBS = -lapt-pkg -lapt-private -lapt-inst -pthread $(LIB)/gtest.a
-LIB_MAKES = apt-pkg/makefile apt-private/makefile apt-inst/makefile
-SOURCE = gtest_runner.cc $(wildcard *-helpers.cc *_test.cc)
-include $(PROGRAM_H)
-
-
-MKDIRS += $(OBJ) $(LIB)
-LOCAL=gtest
-SOURCE=gtest-all
-gtest-OBJS := $(addprefix $(OBJ)/,$(addsuffix .o,$(SOURCE)))
-
-# The rest of the file is based on the example found in
-# /usr/share/doc/libgtest-dev/examples/make/Makefile
-GTEST_DIR = /usr/src/gtest
-
-# Flags passed to the preprocessor.
-# Set Google Test's header directory as a system directory, such that
-# the compiler doesn't generate warnings in Google Test headers.
-#CPPFLAGS += -isystem $(GTEST_DIR)/include
-
-# Flags passed to the C++ compiler.
-CXXFLAGS += -pthread
-# disable some flags for gtest again
-CXXFLAGS+= -Wno-missing-declarations
-CXXFLAGS+= -Wno-missing-field-initializers
-CXXFLAGS+= -Wno-suggest-attribute=pure -Wno-suggest-attribute=const -Wno-suggest-attribute=noreturn
-CXXFLAGS+= -Wno-undef
-
-# All Google Test headers. Usually you shouldn't change this definition.
-GTEST_HEADERS = /usr/include/gtest/*.h \
- /usr/include/gtest/internal/*.h
-
-# House-keeping build targets.
-.PHONY: clean/gtest veryclean/gtest
-clean: clean/gtest
-clean/gtest:
- rm -f $(gtest-OBJS)
-veryclean: veryclean/gtest
-veryclean/gtest: clean/gtest
- rm -f $(LIB)/gtest.a
-
-# Usually you shouldn't tweak such internal variables, indicated by a
-# trailing _.
-GTEST_SRCS_ = $(GTEST_DIR)/src/*.cc $(GTEST_DIR)/src/*.h $(GTEST_HEADERS)
-
-# Builds gtest.a
-# For simplicity and to avoid depending on Google Test's
-# implementation details, the dependencies specified below are
-# conservative and not optimized. This is fine as Google Test
-# compiles fast and for ordinary users its source rarely changes.
-$(gtest-OBJS): $(GTEST_SRCS_)
- echo Compiling $@
- $(CXX) $(CPPFLAGS) -I$(GTEST_DIR) $(CXXFLAGS) -c -o $@ $(GTEST_DIR)/src/$(notdir $(basename $@)).cc
-
-$(LIB)/gtest.a: $(OBJ)/gtest-all.o
- echo Building static library $@
- -rm -f $@
- $(AR) $(ARFLAGS) $@ $^
-
-else
-test:
- @echo "APT uses Googles C++ testing framework for its unit tests"
- @echo "On Debian systems this is available in the 'libgtest-dev' package."
- @echo "Please install it before attempting to run the unit tests."
- $(CC) -I $(BASE)/build/include -M gtest_runner.cc
- exit 100
-endif