Started Node tests (for the new API Node)
This commit is contained in:
parent
2d06df474b
commit
432268917b
57
test/new-api/nodetests.cpp
Normal file
57
test/new-api/nodetests.cpp
Normal file
@ -0,0 +1,57 @@
|
||||
#include "nodetests.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
|
||||
namespace {
|
||||
struct TEST {
|
||||
TEST(): ok(false) {}
|
||||
TEST(bool ok_): ok(ok_) {}
|
||||
TEST(const char *error_): ok(false), error(error_) {}
|
||||
|
||||
bool ok;
|
||||
std::string error;
|
||||
};
|
||||
}
|
||||
|
||||
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
|
||||
|
||||
namespace Test
|
||||
{
|
||||
namespace Node
|
||||
{
|
||||
TEST SimpleScalar()
|
||||
{
|
||||
YAML::Node node = YAML::Node("Hello, World!");
|
||||
YAML_ASSERT(node.Type() == YAML::NodeType::Scalar);
|
||||
YAML_ASSERT(node.as<std::string>() == "Hello, World!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void RunNodeTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||
TEST ret;
|
||||
try {
|
||||
ret = test();
|
||||
} catch(...) {
|
||||
ret.ok = false;
|
||||
}
|
||||
if(ret.ok) {
|
||||
passed++;
|
||||
} else {
|
||||
std::cout << "Node test failed: " << name << "\n";
|
||||
if(ret.error != "")
|
||||
std::cout << ret.error << "\n";
|
||||
}
|
||||
total++;
|
||||
}
|
||||
|
||||
bool RunNodeTests()
|
||||
{
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
|
||||
RunNodeTest(&Node::SimpleScalar, "simple scalar", passed, total);
|
||||
|
||||
std::cout << "Node tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
}
|
||||
}
|
13
test/nodetests.h
Normal file
13
test/nodetests.h
Normal file
@ -0,0 +1,13 @@
|
||||
#ifndef NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
namespace Test {
|
||||
bool RunNodeTests();
|
||||
}
|
||||
|
||||
#endif // NODETESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A6666
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "tests.h"
|
||||
#include "emittertests.h"
|
||||
#include "nodetests.h"
|
||||
#include "parsertests.h"
|
||||
#include "spectests.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
@ -22,6 +23,11 @@ namespace Test
|
||||
if(!RunSpecTests())
|
||||
passed = false;
|
||||
|
||||
#ifndef YAML_CPP_OLD_API
|
||||
if(!RunNodeTests())
|
||||
passed = false;
|
||||
#endif
|
||||
|
||||
if(passed)
|
||||
std::cout << "All tests passed!\n";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user