2014-01-24 00:09:37 +01:00
|
|
|
#include "archive/ArchiveLookup.hxx"
|
2018-08-20 16:19:17 +02:00
|
|
|
#include "util/Compiler.h"
|
2013-10-17 00:19:22 +02:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
#include <gtest/gtest.h>
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
#include <string.h>
|
2013-11-05 17:28:23 +01:00
|
|
|
#include <stdlib.h>
|
2013-10-17 00:19:22 +02:00
|
|
|
|
2018-10-16 19:01:13 +02:00
|
|
|
TEST(ArchiveTest, Lookup)
|
2013-10-17 00:19:22 +02:00
|
|
|
{
|
2013-10-17 00:35:58 +02:00
|
|
|
const char *archive, *inpath, *suffix;
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
char *path = strdup("");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup(".");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("config.h");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("src/foo/bar");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_FALSE(archive_lookup(path, &archive, &inpath, &suffix));
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
2017-12-29 17:12:55 +01:00
|
|
|
fclose(fopen("dummy", "w"));
|
|
|
|
|
|
|
|
path = strdup("dummy/foo/bar");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_TRUE(archive_lookup(path, &archive, &inpath, &suffix));
|
|
|
|
EXPECT_EQ((const char *)path, archive);
|
|
|
|
EXPECT_STREQ(archive, "dummy");
|
|
|
|
EXPECT_STREQ(inpath, "foo/bar");
|
|
|
|
EXPECT_EQ((const char *)nullptr, suffix);
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
|
|
|
|
path = strdup("config.h/foo/bar");
|
2018-10-16 19:01:13 +02:00
|
|
|
EXPECT_TRUE(archive_lookup(path, &archive, &inpath, &suffix));
|
|
|
|
EXPECT_EQ((const char *)path, archive);
|
|
|
|
EXPECT_STREQ(archive, "config.h");
|
|
|
|
EXPECT_STREQ(inpath, "foo/bar");
|
|
|
|
EXPECT_STREQ(suffix, "h");
|
2014-10-24 20:30:48 +02:00
|
|
|
free(path);
|
2013-10-17 00:19:22 +02:00
|
|
|
}
|