From: pius.lee Date: Tue, 10 Feb 2015 03:52:10 +0000 (+0900) Subject: [Common] fix typeutil overflowed very long type X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~476 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ccde1f3fe0da29b759ee1f80169bc6f437b3eea3;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Common] fix typeutil overflowed very long type Change-Id: Iadeef968d7bd421cc42f7c20117dd70abfcf2c4d Signed-off-by: pius.lee --- diff --git a/src/common/typeutil.h b/src/common/typeutil.h index 6c659d17..e46e3540 100644 --- a/src/common/typeutil.h +++ b/src/common/typeutil.h @@ -5,6 +5,7 @@ #ifndef COMMON_TYPEUTIL_H_ #define COMMON_TYPEUTIL_H_ +#include #include #include "common/picojson.h" @@ -61,12 +62,19 @@ IS_TYPE_RANGE(ByteType, -128, 127) IS_TYPE_RANGE(OctetType, 0, 255) IS_TYPE_RANGE(ShortType, -32768, 32767) IS_TYPE_RANGE(UnsignedShortType, 0, 65535) -IS_TYPE_RANGE(LongType, -2147483648, 2147483647) -IS_TYPE_RANGE(UnsignedLongType, 0, 4294967295) -IS_TYPE_RANGE(LongLongType, -9223372036854775808, 9223372036854775807) -IS_TYPE_RANGE(UnsignedLongLongType, 0, 18446744073709551615) +IS_TYPE_RANGE(LongType, -2147483648L, 2147483647L) +IS_TYPE_RANGE(UnsignedLongType, 0, 4294967295U) +IS_TYPE_RANGE(LongLongType, -9223372036854775807LL, 9223372036854775807LL) +IS_TYPE_RANGE(UnsignedLongLongType, 0, 18446744073709551615ULL) #undef IS_TYPE_RANGE +bool IsEnum(const value& arg, const std::string& name, + const std::set& values) { + const value& v = arg.get(name); + return v.is() && + values.find(v.get()) != values.end(); +} + } // namespace WIDLTypeValidator namespace CTypeConveter { @@ -106,7 +114,8 @@ int main(void) { "\"longlong1\": -9223372036854775808," "\"longlong2\": 9223372036854775807," "\"ulonglong\": 18446744073709551615," - "\"zero\": 0" + "\"zero\": 0," + "\"enum\": \"enum\"" "}"; picojson::value v; std::string err = picojson::parse(v, tc, tc + strlen(tc)); @@ -115,6 +124,7 @@ int main(void) { using common::WIDLTypeValidator::WIDLType; using common::WIDLTypeValidator::IsType; + using common::WIDLTypeValidator::IsEnum; #define TC_POSITIVE(name, wtype) \ printf("%s positive %s : %s\n", #wtype, \ @@ -242,6 +252,17 @@ int main(void) { TC_NEGATIVE("array2", WIDLType::UnsignedLongLongType); TC_NEGATIVE("boolean", WIDLType::UnsignedLongLongType); + std::string values[] = { + "enum", "foo", "bar" + }; + std::set enums(values, values+3); + bool enum_p = IsEnum(v, "enum", enums); + printf("%s positive %s : %s\n", "enum", enum_p ? "pass" : "fail", + v.get("enum").to_str().c_str()); + bool enum_n = IsEnum(v, "xxx", enums); + printf("%s negative %s : %s\n", "enum", !enum_n ? "pass" : "fail", + v.get("enum").to_str().c_str()); + #undef TC_POSITIVE #undef TC_NEGATIVE }