074339040b
And replace it with the function file_init(). Let's take this chance to rework parts of the unit test as well. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
/**
|
|
* Copyright 2014 (c) Anna Schumaker.
|
|
*/
|
|
#include <core/tags/generic.h>
|
|
#include "../test.h"
|
|
|
|
static void test_generic_tag()
|
|
{
|
|
GenericTag tag("Generic Tag");
|
|
file f;
|
|
|
|
test_equal(tag.name(), (std::string)"Generic Tag");
|
|
test_equal(tag.lowercase(), (std::string)"generic tag");
|
|
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
|
|
|
file_init(&f, "generic_tag", 0);
|
|
file_open(&f, OPEN_WRITE);
|
|
tag.write(f);
|
|
file_close(&f);
|
|
|
|
tag = GenericTag();
|
|
test_equal(tag.name(), (std::string)"");
|
|
test_equal(tag.lowercase(), (std::string)"");
|
|
test_equal(tag.primary_key(), (std::string)"");
|
|
|
|
file_open(&f, OPEN_READ);
|
|
tag.read(f);
|
|
file_close(&f);
|
|
|
|
test_equal(tag.name(), (std::string)"Generic Tag");
|
|
test_equal(tag.lowercase(), (std::string)"generic tag");
|
|
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
|
|
|
tag = GenericTag(tag);
|
|
test_equal(tag.name(), (std::string)"Generic Tag");
|
|
test_equal(tag.lowercase(), (std::string)"generic tag");
|
|
test_equal(tag.primary_key(), (std::string)"Generic Tag");
|
|
}
|
|
|
|
static void test_generic_tag_comparison()
|
|
{
|
|
GenericTag A("A"), a("a"), B("B"), empty("");
|
|
|
|
test_equal(A.compare(&A), 0);
|
|
test_equal(a.compare(&a), 0);
|
|
test_equal(A.compare(&B), -1);
|
|
test_equal(B.compare(&A), 1);
|
|
|
|
test_equal(empty.compare(&A), 1);
|
|
test_equal(A.compare(&empty), -1);
|
|
}
|
|
|
|
DECLARE_UNIT_TESTS(
|
|
UNIT_TEST("Generic Tag", test_generic_tag),
|
|
UNIT_TEST("Generic Tag Comparison", test_generic_tag_comparison),
|
|
);
|