summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/controls/control_value.cpp110
1 files changed, 88 insertions, 22 deletions
diff --git a/test/controls/control_value.cpp b/test/controls/control_value.cpp
index a1ffa842..37f41530 100644
--- a/test/controls/control_value.cpp
+++ b/test/controls/control_value.cpp
@@ -19,46 +19,112 @@ class ControlValueTest : public Test
protected:
int run()
{
- ControlValue integer(1234);
- ControlValue boolean(true);
+ /*
+ * None type.
+ */
+ ControlValue value;
+ if (!value.isNone() || value.isArray()) {
+ cerr << "Empty value is non-null" << endl;
+ return TestFail;
+ }
- /* Just a string conversion output test... no validation */
- cout << "Int: " << integer.toString()
- << " Bool: " << boolean.toString()
- << endl;
+ /*
+ * Bool type.
+ */
+ value.set(true);
+ if (value.isNone() || value.isArray() ||
+ value.type() != ControlTypeBool) {
+ cerr << "Control type mismatch after setting to bool" << endl;
+ return TestFail;
+ }
- if (integer.get<int32_t>() != 1234) {
- cerr << "Failed to get Integer" << endl;
+ if (value.get<bool>() != true) {
+ cerr << "Control value mismatch after setting to bool" << endl;
return TestFail;
}
- if (boolean.get<bool>() != true) {
- cerr << "Failed to get Boolean" << endl;
+ if (value.toString() != "true") {
+ cerr << "Control string mismatch after setting to bool" << endl;
return TestFail;
}
- /* Test an uninitialised value, and updating it. */
+ /*
+ * Integer8 type.
+ */
+ value.set(static_cast<uint8_t>(42));
+ if (value.isNone() || value.isArray() ||
+ value.type() != ControlTypeByte) {
+ cerr << "Control type mismatch after setting to uint8_t" << endl;
+ return TestFail;
+ }
- ControlValue value;
- if (!value.isNone()) {
- cerr << "Empty value is non-null" << endl;
+ if (value.get<uint8_t>() != 42) {
+ cerr << "Control value mismatch after setting to uint8_t" << endl;
return TestFail;
}
- value.set<bool>(true);
- if (value.isNone()) {
- cerr << "Failed to set an empty object" << endl;
+ if (value.toString() != "42") {
+ cerr << "Control string mismatch after setting to uint8_t" << endl;
return TestFail;
}
- if (value.get<bool>() != true) {
- cerr << "Failed to get Booleans" << endl;
+ /*
+ * Integer32 type.
+ */
+ value.set(0x42000000);
+ if (value.isNone() || value.isArray() ||
+ value.type() != ControlTypeInteger32) {
+ cerr << "Control type mismatch after setting to int32_t" << endl;
+ return TestFail;
+ }
+
+ if (value.get<int32_t>() != 0x42000000) {
+ cerr << "Control value mismatch after setting to int32_t" << endl;
+ return TestFail;
+ }
+
+ if (value.toString() != "1107296256") {
+ cerr << "Control string mismatch after setting to int32_t" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Integer64 type.
+ */
+ value.set(static_cast<int64_t>(-42));
+ if (value.isNone() || value.isArray() ||
+ value.type() != ControlTypeInteger64) {
+ cerr << "Control type mismatch after setting to int64_t" << endl;
+ return TestFail;
+ }
+
+ if (value.get<int64_t>() != -42) {
+ cerr << "Control value mismatch after setting to int64_t" << endl;
+ return TestFail;
+ }
+
+ if (value.toString() != "-42") {
+ cerr << "Control string mismatch after setting to int64_t" << endl;
+ return TestFail;
+ }
+
+ /*
+ * Float type.
+ */
+ value.set(-0.42f);
+ if (value.isNone() || value.isArray() ||
+ value.type() != ControlTypeFloat) {
+ cerr << "Control type mismatch after setting to float" << endl;
+ return TestFail;
+ }
+
+ if (value.get<float>() != -0.42f) {
+ cerr << "Control value mismatch after setting to float" << endl;
return TestFail;
}
- value.set<int32_t>(10);
- if (value.get<int32_t>() != 10) {
- cerr << "Failed to get Integer" << endl;
+ if (value.toString() != "-0.420000") {
+ cerr << "Control string mismatch after setting to float" << endl;
return TestFail;
}