Files
ArduinoJson/JsonGeneratorTests/JsonHashTableTests.cpp

49 lines
1022 B
C++
Raw Normal View History

2014-06-27 13:00:27 +02:00
#include "CppUnitTest.h"
#include "JsonHashTable.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
namespace JsonGeneratorTests
{
TEST_CLASS(JsonHashTableTests)
{
JsonHashTable<2> hash;
public:
TEST_METHOD(Empty)
{
2014-06-27 13:09:52 +02:00
jsonIs("{}");
2014-06-27 13:00:27 +02:00
}
TEST_METHOD(OneString)
{
add("key", "value");
2014-06-27 13:09:52 +02:00
jsonIs("{\"key\":\"value\"}");
}
TEST_METHOD(TwoStrings)
{
add("key1", "value1");
add("key2", "value2");
jsonIs("{\"key1\":\"value1\",\"key2\":\"value2\"}");
}
2014-06-27 13:00:27 +02:00
private:
template<typename T>
void add(const char* key, T value)
{
hash.add(key, value);
}
2014-06-27 13:09:52 +02:00
void jsonIs(const char* expected)
2014-06-27 13:00:27 +02:00
{
char buffer[256];
hash.writeTo(buffer, sizeof(buffer));
Assert::AreEqual(expected, buffer);
}
};
}