int32_t TestRunner::cppVariantToInt32(const CppVariant& value) { if (value.isNumber()) return value.toInt32(); if (value.isString()) { string stringSource = value.toString(); const char* source = stringSource.data(); char* end; long number = strtol(source, &end, 10); if (end == source + stringSource.length() && number >= numeric_limits<int32_t>::min() && number <= numeric_limits<int32_t>::max()) return static_cast<int32_t>(number); } printErrorMessage("Invalid value for preference. Expected integer value."); return 0; }
// Need these conversions because the format of the value for booleans // may vary - for example, on mac "1" and "0" are used for boolean. bool TestRunner::cppVariantToBool(const CppVariant& value) { if (value.isBool()) return value.toBoolean(); if (value.isNumber()) return value.toInt32(); if (value.isString()) { string valueString = value.toString(); if (valueString == "true" || valueString == "1") return true; if (valueString == "false" || valueString == "0") return false; } printErrorMessage("Invalid value. Expected boolean value."); return false; }