test_archive.cxx 1.03 KB
Newer Older
1
#include "archive/ArchiveLookup.hxx"
2
#include "util/Compiler.h"
3

4
#include <gtest/gtest.h>
5 6

#include <string.h>
7
#include <stdlib.h>
8

9
TEST(ArchiveTest, Lookup)
10 11
{
	char *path = strdup("");
12
	EXPECT_THROW(archive_lookup(path), std::system_error);
13
	free(path);
14 15

	path = strdup(".");
16
	EXPECT_FALSE(archive_lookup(path));
17
	free(path);
18 19

	path = strdup("config.h");
20
	EXPECT_FALSE(archive_lookup(path));
21
	free(path);
22 23

	path = strdup("src/foo/bar");
24
	EXPECT_THROW(archive_lookup(path), std::system_error);
25
	free(path);
26

27 28 29
	fclose(fopen("dummy", "w"));

	path = strdup("dummy/foo/bar");
30 31 32 33 34
	auto result = archive_lookup(path);
	EXPECT_TRUE(result);
	EXPECT_EQ((const char *)path, result.archive.c_str());
	EXPECT_STREQ(result.archive.c_str(), "dummy");
	EXPECT_STREQ(result.inside.c_str(), "foo/bar");
35
	free(path);
36 37

	path = strdup("config.h/foo/bar");
38 39 40 41 42
	result = archive_lookup(path);
	EXPECT_TRUE(result);
	EXPECT_EQ((const char *)path, result.archive.c_str());
	EXPECT_STREQ(result.archive.c_str(), "config.h");
	EXPECT_STREQ(result.inside.c_str(), "foo/bar");
43
	free(path);
44
}