diff options
author | David Kalnischkies <david@kalnischkies.de> | 2014-04-16 17:09:37 +0200 |
---|---|---|
committer | David Kalnischkies <david@kalnischkies.de> | 2014-04-16 18:36:14 +0200 |
commit | f00832cc273e52a47fb88e49849891b771de4e17 (patch) | |
tree | eedd6b1e1c873c7e3e8f614a0ac8ca5c3b7e37b9 /test/libapt/tagfile_test.cc | |
parent | bb93178b8b5c2f8021977dbc34066f0d0fb8b9b9 (diff) |
use Google C++ Testing Framework for libapt tests
My commit 45df0ad2 from 26. Nov 2009 had a little remark:
"The commit also includes a very very simple testapp."
This was never intended to be permanent, but as usually…
The commit adds the needed make magic to compile gtest statically
as it is required and links it against a small runner. All previous
testcase binaries are reimplemented in gtest and combined in this
runner. While most code is a 1:1 translation some had to be rewritten
like compareversion_test.cc, but the coverage remains the same.
Diffstat (limited to 'test/libapt/tagfile_test.cc')
-rw-r--r-- | test/libapt/tagfile_test.cc | 62 |
1 files changed, 18 insertions, 44 deletions
diff --git a/test/libapt/tagfile_test.cc b/test/libapt/tagfile_test.cc index aaf46e3e9..1bac75b55 100644 --- a/test/libapt/tagfile_test.cc +++ b/test/libapt/tagfile_test.cc @@ -8,55 +8,29 @@ #include <string.h> #include <unistd.h> -#include "assert.h" +#include <gtest/gtest.h> -char *tempfile = NULL; -int tempfile_fd = -1; +#include "file-helpers.h" -static void remove_tmpfile(void) -{ - if (tempfile_fd > 0) - close(tempfile_fd); - if (tempfile != NULL) { - unlink(tempfile); - free(tempfile); - } -} - -int main() +TEST(TagFileTest,SingleField) { FileFd fd; - const char contents[] = "FieldA-12345678: the value of the field"; - atexit(remove_tmpfile); - tempfile = strdup("apt-test.XXXXXXXX"); - tempfile_fd = mkstemp(tempfile); - - /* (Re-)Open (as FileFd), write and seek to start of the temp file */ - equals(fd.OpenDescriptor(tempfile_fd, FileFd::ReadWrite), true); - equals(fd.Write(contents, strlen(contents)), true); - equals(fd.Seek(0), true); + createTemporaryFile("singlefield", fd, NULL, "FieldA-12345678: the value of the field"); pkgTagFile tfile(&fd); pkgTagSection section; - equals(tfile.Step(section), true); - - /* It has one field */ - equals(section.Count(), 1); - - /* ... and it is called FieldA-12345678 */ - equals(section.Exists("FieldA-12345678"), true); - - /* its value is correct */ - equals(section.FindS("FieldA-12345678"), std::string("the value of the field")); - /* A non-existent field has an empty string as value */ - equals(section.FindS("FieldB-12345678"), std::string()); - - /* ... and Exists does not lie about missing fields... */ - equalsNot(section.Exists("FieldB-12345678"), true); - - /* There is only one section in this tag file */ - equals(tfile.Step(section), false); - - /* clean up handled by atexit handler, so just return here */ - return 0; + ASSERT_TRUE(tfile.Step(section)); + + // It has one field + EXPECT_EQ(1, section.Count()); + // ... and it is called FieldA-12345678 + EXPECT_TRUE(section.Exists("FieldA-12345678")); + // its value is correct + EXPECT_EQ("the value of the field", section.FindS("FieldA-12345678")); + // A non-existent field has an empty string as value + EXPECT_EQ("", section.FindS("FieldB-12345678")); + // ... and Exists does not lie about missing fields... + EXPECT_FALSE(section.Exists("FieldB-12345678")); + // There is only one section in this tag file + EXPECT_FALSE(tfile.Step(section)); } |