コード例 #1
0
TEST_F(TestNumberSanity, Valid2)
{
	JDomParser parser;
	EXPECT_TRUE(parser.parse("[1.0]", *schema.get()));
	JValue parsed = parser.getDom();
	EXPECT_TRUE(parsed.isArray());
	EXPECT_TRUE(JValidator::isValid(parsed, *schema.get()));
}
コード例 #2
0
ファイル: JValue.cpp プロジェクト: FreeWebOS/libpbnjson
bool JValue::put(const JValue& key, const JValue& value)
{
#if PBNJSON_ZERO_COPY_STL_STR
	m_children.push_back(value.m_input);
	m_children.push_back(key.m_input);
	m_children.insert(m_children.end(), value.m_children.begin(), value.m_children.end());
#endif
	return jobject_set2(m_jval, key.peekRaw(), value.peekRaw());
}
コード例 #3
0
ファイル: JConstructor.cpp プロジェクト: alaineman/PowerGrid
/**
 * Gets the method id matching the given arguments.
 *
 */
jmethodID JConstructor::getMethodID( const JClass* jClass, const JArguments& arguments ) {

  /* We cache the jmethodID locally, so if we've already found it,
   * we don't need to go looking for it again.
   */
  if ( mMethodID ) {
    return mMethodID;
  }

  /* If we don't already have the jmethodID, we need to determine
   * the signature of this method.
   */

  /* We construct this signature with a void return type,
   * because the return type for constructors is void.
   */
  JSignature signature( *JVoid::staticGetJavaJniClass() ); 
  typedef list<JValue*> ValueList;
  ValueList args = arguments.asList();
  
  ValueList::iterator i = args.begin();
  ValueList::iterator end = args.end();

  for ( ; i != end; ++i ) {
    JValue* value = *i;
    signature << *value->getJavaJniClass();
  }

  string methodSignature = signature.toString();

  /* Now that we have the signature for the method, we could look
   * in a global cache for the jmethodID corresponding to this method,
   * but for now, we'll always find it.
   */
  JNIEnv* env = helper::attach();

  mMethodID = env->GetMethodID( jClass->getClass(), "<init>", methodSignature.c_str() );

  if ( mMethodID == NULL ) {
    string msg = string( "JConstructor::getMethodID\n" ) +
                 "Unable to find a constructor for " + jClass->getName() + "\n" +
                 "The signature is <" + methodSignature + ">";
		try
		{
			helper::catchAndThrow();
		}
		catch (JNIException e)
		{
			msg.append("\ncaused by:\n");
			msg.append(e.what());
		}
    throw JNIException( msg );
  }

  return mMethodID;
}
コード例 #4
0
ファイル: JValue.cpp プロジェクト: FreeWebOS/libpbnjson
bool JValue::append(const JValue& value)
{
#if PBNJSON_ZERO_COPY_STL_STR
	if (!value.m_input.empty() || (value.isString() && value.asString().empty())) {
		m_children.push_back(value.m_input);
	}
	m_children.insert(m_children.end(), value.m_children.begin(), value.m_children.end());
#endif
	return jarray_set(m_jval, jarray_size(m_jval), value.peekRaw());
}
コード例 #5
0
TEST_F(TestNumberSanity, Valid3)
{
	char const *const INPUT =
		"[2394309382309842309234825.62345235323253253220398443213241234"
		"123431413e90234098320982340924382340982349023423498234908234]";

	JDomParser parser;
	EXPECT_TRUE(parser.parse(INPUT, *schema.get()));
	JValue parsed = parser.getDom();
	EXPECT_TRUE(parsed.isArray());
	EXPECT_TRUE(JValidator::isValid(parsed, *schema.get()));
}
コード例 #6
0
ファイル: 01.cpp プロジェクト: crockeo/jsonr
// Testing the parseJSON function for parsing a string.
int runTest01() {
    JValue sVal = parseJSON("\"hello\"");
    JValue sqVal = parseJSON("\"word up\"");
    JValue midVal = parseJSON("\"with mid \\\" quotes!!!\"");

    if (sVal.isString() && sVal.jString().compare("hello") == 0 &&
        sqVal.isString() && sqVal.jString().compare("word up") == 0 &&
        midVal.isString() && midVal.jString().compare("with mid \" quotes!!!") == 0)
        return 0;

    return 1;
}
コード例 #7
0
ファイル: JValue.cpp プロジェクト: FreeWebOS/libpbnjson
static bool numEqual(const JValue& jnum, const T& nativeNum)
{
	T num;
	if (jnum.asNumber(num) == CONV_OK)
		return num == nativeNum;
	return false;
}
コード例 #8
0
void TestRegression::testSysmgrFailure_data()
{
	INIT_SCHEMA_TEST_DATA;

	JValue faultyInput;
	std::string input;
	std::string validSchema;

	validSchema = "{\"type\":\"object\",\"properties\":{\"quicklaunch\":{\"type\":\"boolean\",\"optional\":true},\"launcher\":{\"type\":\"boolean\",\"optional\":true},\"universal search\":{\"type\":\"boolean\",\"optional\":true}},\"additionalProperties\":false}";
	faultyInput = Object();
	faultyInput.put("universal search", false);
	faultyInput.put("launcher", false);
	toString(faultyInput, input);

	QTest::newRow("schema test from sysmgr crash") << input << validSchema << true;
}
コード例 #9
0
ファイル: JValue.cpp プロジェクト: FreeWebOS/libpbnjson
bool JValue::put(size_t index, const JValue& value)
{
#if PBNJSON_ZERO_COPY_STL_STR
	m_children.push_back(value.m_input);
	m_children.insert(m_children.end(), value.m_children.begin(), value.m_children.end());
#endif
	return jarray_set(m_jval, index, value.peekRaw());
}
コード例 #10
0
ファイル: JGenerator.cpp プロジェクト: FreeWebOS/libpbnjson
std::string JGenerator::serialize(const JValue &val, bool quoteSingleString)
{
	const char *str = jvalue_tostring_simple(val.peekRaw());
	if (UNLIKELY(str == NULL)) {
		return "";
	}

	if (!quoteSingleString && val.isString())
	{
		size_t length = strlen(str);
		if ( (length >= 2) &&
			 (str[0] == '"') &&
			 (str[length-1] == '"') )
		{
			 return std::string(str+1, length-2);
		}
	}

	return str;
}
コード例 #11
0
void TestRegression::testNOV99444_data()
{
	INIT_SCHEMA_TEST_DATA;

	std::string input;

	std::string faultySchema =
	"{"
	        "\"type\" : \"object\","
	        "\"properties\" : {"
	                "\"errorCode\" : {"
	                        "\"type\" : \"integer\";"
	                "}"
	        "}"
	"}";

	std::string validSchema =
	"{"
	        "\"type\" : \"object\","
	        "\"properties\" : {"
	                "\"errorCode\" : {"
	                        "\"type\" : \"integer\""
	                "}"
	        "}"
	"}";

	JValue faultyInput;

	faultyInput = Object();
	faultyInput.put("returnValue", false);
	faultyInput.put("errorCode", -1);
	faultyInput.put("errorText", "Launch helper exited with unknown return code 0");
	toString(faultyInput, input);
	QTest::newRow("bad schema test") << input << faultySchema << false;
	QTest::newRow("schema test from bug") << input << validSchema << true;
}
コード例 #12
0
ファイル: JGenerator.cpp プロジェクト: FreeWebOS/libpbnjson
bool JGenerator::toString(const JValue &obj, const JSchema& schema, std::string &asStr)
{
	if (m_resolver) {
		JSchemaResolverWrapper resolverWrapper(m_resolver);
		JSchemaResolver schemaresolver;
		schemaresolver.m_resolve = &(resolverWrapper.sax_schema_resolver);
		schemaresolver.m_userCtxt = &resolverWrapper;
		schemaresolver.m_inRecursion = 0;
		if (!jschema_resolve_ex(schema.peek(), &schemaresolver)) {
			asStr = "";
			return false;
		}
	}
	const char *str = jvalue_tostring(obj.peekRaw(), schema.peek());

	if (str == NULL) {
		asStr = "";
		return false;
	}
	asStr = str;
	return true;
}