mpd/test/test_archive.cxx

45 lines
1.0 KiB
C++
Raw Normal View History

2014-01-24 00:09:37 +01:00
#include "archive/ArchiveLookup.hxx"
2018-08-20 16:19:17 +02:00
#include "util/Compiler.h"
2018-10-16 19:01:13 +02:00
#include <gtest/gtest.h>
#include <string.h>
#include <stdlib.h>
2018-10-16 19:01:13 +02:00
TEST(ArchiveTest, Lookup)
{
char *path = strdup("");
EXPECT_THROW(archive_lookup(path), std::system_error);
2014-10-24 20:30:48 +02:00
free(path);
path = strdup(".");
EXPECT_FALSE(archive_lookup(path));
2014-10-24 20:30:48 +02:00
free(path);
path = strdup("config.h");
EXPECT_FALSE(archive_lookup(path));
2014-10-24 20:30:48 +02:00
free(path);
path = strdup("src/foo/bar");
EXPECT_THROW(archive_lookup(path), std::system_error);
2014-10-24 20:30:48 +02:00
free(path);
fclose(fopen("dummy", "w"));
path = strdup("dummy/foo/bar");
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");
2014-10-24 20:30:48 +02:00
free(path);
path = strdup("config.h/foo/bar");
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");
2014-10-24 20:30:48 +02:00
free(path);
}