487 lines
15 KiB
C++
487 lines
15 KiB
C++
/**
|
|
* @author Edouard DUPIN
|
|
* @copyright 2017, Edouard DUPIN, all right reserved
|
|
* @license MPL-2 (see license file)
|
|
*/
|
|
#include <test-debug/debug.hpp>
|
|
#include <etest/etest.hpp>
|
|
#include "testInterface.hpp"
|
|
|
|
|
|
TEST(testVariable, noVariable) {
|
|
testInterface system;
|
|
bool ret = system.execute("// plop");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), false);
|
|
}
|
|
|
|
TEST(testVariable, declare_int) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int result;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
}
|
|
|
|
|
|
|
|
TEST(testVariable, declare_int_init_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int result(55);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 55);
|
|
}
|
|
|
|
TEST(testVariable, declare_int_init_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int result = 55;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 55);
|
|
}
|
|
|
|
TEST(testVariable, declare_int32_init_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result(55);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 55);
|
|
}
|
|
|
|
TEST(testVariable, declare_int32_init_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 55;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 55);
|
|
}
|
|
|
|
TEST(testVariable, declare_int64_init_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int64 result(55);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger64("result"), true);
|
|
EXPECT_EQ(system.getInteger64("result"), 55);
|
|
}
|
|
|
|
TEST(testVariable, declare_int64_init_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int64 result = 55;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger64("result"), true);
|
|
EXPECT_EQ(system.getInteger64("result"), 55);
|
|
}
|
|
|
|
|
|
TEST(testVariable, boolean_true_init_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable bool result(true);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
TEST(testVariable, boolean_true_init_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable bool result = true;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), true);
|
|
}
|
|
|
|
TEST(testVariable, boolean_false_init_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable bool result(false);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
}
|
|
|
|
TEST(testVariable, boolean_false_init_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable bool result = false;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isBoolean("result"), true);
|
|
EXPECT_EQ(system.getBoolean("result"), false);
|
|
}
|
|
|
|
TEST(testVariable, integer_min_int32) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = -2147483648;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), -2147483648);
|
|
}
|
|
|
|
TEST(testVariable, integer_max_int32) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 2147483647;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 2147483647);
|
|
}
|
|
|
|
TEST(testVariable, integer_hexadecmal_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 0x12345678;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 0x12345678);
|
|
}
|
|
|
|
TEST(testVariable, integer_hexadecmal_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 0xABCDEF00;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 0xABCDEF00);
|
|
}
|
|
|
|
TEST(testVariable, integer_hexadecmal_3) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = -0x5;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), -5);
|
|
}
|
|
TEST(testVariable, integer_hexadecmal_4) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 0xFFFFFFFF;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), -1);
|
|
}
|
|
|
|
|
|
TEST(testVariable, integer_float32_0) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float32 result(0.32452);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isFloat("result"), true);
|
|
EXPECT_EQ(system.getFloat("result"), 0.32452);
|
|
}
|
|
|
|
TEST(testVariable, integer_float32_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float32 result = 0.32452;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isFloat("result"), true);
|
|
EXPECT_EQ(system.getFloat("result"), 0.32452);
|
|
}
|
|
|
|
TEST(testVariable, integer_float32_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float32 result = -992345.23;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), -992345.23);
|
|
}
|
|
|
|
TEST(testVariable, integer_float32_3) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float32 result = 3.45e2;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), 3.45e2);
|
|
}
|
|
|
|
TEST(testVariable, integer_float_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float result = 3.45e2;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), 3.45e2);
|
|
}
|
|
|
|
|
|
|
|
TEST(testVariable, integer_float64_0) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float64 result(0.32452);");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), 0.32452);
|
|
}
|
|
TEST(testVariable, integer_float64_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float64 result = 0.32452;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), 0.32452);
|
|
}
|
|
|
|
TEST(testVariable, integer_float64_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float64 result = -992345.23;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), -992345.23);
|
|
}
|
|
|
|
TEST(testVariable, integer_float64_3) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable float64 result = 3.45e2;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isDouble("result"), true);
|
|
EXPECT_EQ(system.getDouble("result"), 3.45e2);
|
|
}
|
|
|
|
TEST(testVariable, integer_octal_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = 0377;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 255);
|
|
}
|
|
/*
|
|
TEST(testVariable, null_element) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable int32 result = null;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isNull("result"), true);
|
|
}
|
|
*/
|
|
|
|
TEST(testVariable, string_0) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable string result(\"hello\");");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isString("result"), true);
|
|
EXPECT_EQ(system.getString("result"), "hello");
|
|
}
|
|
TEST(testVariable, string_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable string result = \"hello\";");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isString("result"), true);
|
|
EXPECT_EQ(system.getString("result"), "hello");
|
|
}
|
|
|
|
TEST(testVariable, string_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable string result = 'hello';");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isString("result"), true);
|
|
EXPECT_EQ(system.getString("result"), "hello");
|
|
}
|
|
|
|
TEST(testVariable, string_1_special_element) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable string result = \"h\\\\n\\\\r\\\"'ello\";");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isString("result"), true);
|
|
EXPECT_EQ(system.getString("result"), "h\\n\\r\"'ello");
|
|
}
|
|
|
|
TEST(testVariable, string_2_special_element) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable string result = 'h\\\\n\\\\r\"\\\'ello';");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isString("result"), true);
|
|
EXPECT_EQ(system.getString("result"), "h\\n\\r\"'ello");
|
|
}
|
|
|
|
|
|
//////////////////////////////////////////////////////
|
|
// undefined
|
|
//////////////////////////////////////////////////////
|
|
/*
|
|
TEST(testVariable, undef_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result;");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isUndefined("result"), true);
|
|
}
|
|
TEST(testVariable, undef_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result; if ((\"\"+result) != \"undefined\") result=1;");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isUndefined("result"), true);
|
|
}
|
|
|
|
TEST(testVariable, undef_property) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result={}; if ((\"\"+result.noProperty) != \"undefined\") result=1;");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), false);
|
|
}
|
|
|
|
TEST(testVariable, undef_to_null) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result; if (result == null) result=1;");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
}
|
|
|
|
TEST(testVariable, undef_to_null_type) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result; if (result === null) result=1;");
|
|
//TEST_INFO(" '" << system.getString("result") << "'");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), false);
|
|
}
|
|
*/
|
|
//////////////////////////////////////////////////////
|
|
// null
|
|
//////////////////////////////////////////////////////
|
|
/*
|
|
TEST(testVariable, undefined_and_null_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (undefined == null) result=1;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 1);
|
|
}
|
|
TEST(testVariable, undefined_and_null_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (undefined === null) result=1;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 0);
|
|
}
|
|
TEST(testVariable, undefined_and_null_3) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (null != undefined) result=1;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 0);
|
|
}
|
|
|
|
TEST(testVariable, undefined_and_null_4) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = 0; if (null === undefined) result=1;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isInteger32("result"), true);
|
|
EXPECT_EQ(system.getInteger32("result"), 0);
|
|
}
|
|
*/
|
|
|
|
//////////////////////////////////////////////////////
|
|
// array
|
|
//////////////////////////////////////////////////////
|
|
/*
|
|
TEST(testVariable, array_declare_1) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = [];");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isArray("result"), true);
|
|
}
|
|
|
|
TEST(testVariable, array_declare_2) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = [10,11,12]; variable a=result[0]; variable b=result[2];");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isArray("result"), true);
|
|
EXPECT_EQ(system.exist("a"), true);
|
|
EXPECT_EQ(system.isInteger32("a"), true);
|
|
EXPECT_EQ(system.getInteger32("a"), 10);
|
|
EXPECT_EQ(system.exist("b"), true);
|
|
EXPECT_EQ(system.isInteger32("b"), true);
|
|
EXPECT_EQ(system.getInteger32("b"), 12);
|
|
}
|
|
|
|
TEST(testVariable, array_declare_polymorph) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = [10,11.55,\"hello\"]; variable a=result[0]; variable b=result[1]; variable c=result[2];");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isArray("result"), true);
|
|
EXPECT_EQ(system.exist("a"), true);
|
|
EXPECT_EQ(system.isInteger32("a"), true);
|
|
EXPECT_EQ(system.getInteger32("a"), 10);
|
|
EXPECT_EQ(system.exist("b"), true);
|
|
EXPECT_EQ(system.isDouble("b"), true);
|
|
EXPECT_EQ(system.getDouble("b"), 11.55);
|
|
EXPECT_EQ(system.exist("c"), true);
|
|
EXPECT_EQ(system.isString("c"), true);
|
|
EXPECT_EQ(system.getString("c"), "hello");
|
|
}
|
|
|
|
|
|
|
|
TEST(testVariable, array_asign) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = [10,11]; result[0] = 5; result[5] = 99; variable a=result[0]; variable b=result[5]; variable c=result[1]; result[1] = 4;");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isArray("result"), true);
|
|
EXPECT_EQ(system.exist("a"), true);
|
|
EXPECT_EQ(system.isInteger32("a"), true);
|
|
EXPECT_EQ(system.getInteger32("a"), 5);
|
|
EXPECT_EQ(system.exist("b"), true);
|
|
EXPECT_EQ(system.isInteger32("b"), true);
|
|
EXPECT_EQ(system.getInteger32("b"), 99);
|
|
EXPECT_EQ(system.exist("c"), true);
|
|
EXPECT_EQ(system.isInteger32("c"), true);
|
|
EXPECT_EQ(system.getInteger32("c"), 11);
|
|
}
|
|
|
|
|
|
TEST(testVariable, array_asign_reference) {
|
|
testInterface system;
|
|
bool ret = system.execute("variable result = [10,11]; variable result2=result; result2[0] = 5; variable a=result[0];");
|
|
EXPECT_EQ(ret, true);
|
|
EXPECT_EQ(system.exist("result"), true);
|
|
EXPECT_EQ(system.isArray("result"), true);
|
|
EXPECT_EQ(system.exist("a"), true);
|
|
EXPECT_EQ(system.isInteger32("a"), true);
|
|
EXPECT_EQ(system.getInteger32("a"), 5);
|
|
}
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|