Unit tests for SmartRest
Dependencies: C027 SmartRest mbed
Diff: values/IntegerValueTest.cpp
- Revision:
- 0:789029e49ea1
diff -r 000000000000 -r 789029e49ea1 values/IntegerValueTest.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/values/IntegerValueTest.cpp Mon Mar 24 10:12:45 2014 +0000 @@ -0,0 +1,37 @@ +#include "IntegerValueTest.h" +#include <stdio.h> +#include <assert.h> +#include <string.h> + +IntegerValueTest::IntegerValueTest() +{ +} + +void IntegerValueTest::test() +{ + testValue(0, "0"); + testValue(-1, "-1"); + testValue(400, "400"); + testValue(-123456, "-123456"); + testValue(123456, "123456"); + testValue(123123123, "123123123"); +} + +void IntegerValueTest::testValue(long number, const char *expected) +{ + printf("Expecting '%s' for number %d\n", expected, number); + IntegerValue value(number); + assert(value.length() == strlen(expected)); + assert(value.valueType() == VALUE_INTEGER); + assert(value.integerValue() == number); + value.write(sink); + assert(strcmp(expected, sink.value()) == 0); + sink.clear(); + + Value *copy = value.copy(); + assert(copy->length() == value.length()); + assert(copy->integerValue() == value.integerValue()); + assert(copy->valueType() == value.valueType()); + delete copy; +} +