예제 #1
0
static wi_runtime_instance_t * _wi_plist_instance_for_node(xmlNodePtr node) {
	wi_string_t		*name;
	
	name = wi_xml_node_name(node);

	if(wi_is_equal(name, WI_STR("dict")))
		return wi_dictionary();
	else if(wi_is_equal(name, WI_STR("array")))
		return wi_array();

	wi_error_set_libwired_error_with_format(WI_ERROR_PLIST_READFAILED,
		WI_STR("Content \"%@\" is not \"dict\" or \"array\""), name);
	
	return NULL;
}
예제 #2
0
void wi_test_runtime_invalid(void) {
    WI_TEST_ASSERT_NULL(wi_runtime_class_with_name(WI_STR("foo")), "");
    WI_TEST_ASSERT_NULL(wi_runtime_class_with_id(1337), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id_for_class(NULL), WI_RUNTIME_ID_NULL, "");
    
    WI_TEST_ASSERT_NULL(wi_runtime_class("foo"), "");
    WI_TEST_ASSERT_NULL(wi_runtime_class_name("foo"), "");
    WI_TEST_ASSERT_EQUALS(wi_runtime_id("foo"), WI_RUNTIME_ID_NULL, "");

    WI_TEST_ASSERT_NULL(wi_retain(NULL), "");
    WI_TEST_ASSERT_EQUALS(wi_retain_count(NULL), 0U, "");
    WI_TEST_ASSERT_NULL(wi_copy(NULL), "");
    WI_TEST_ASSERT_NULL(wi_mutable_copy(NULL), "");
    WI_TEST_ASSERT_TRUE(wi_is_equal(NULL, NULL), "");
    WI_TEST_ASSERT_FALSE(wi_is_equal(NULL, "foo"), "");
    WI_TEST_ASSERT_FALSE(wi_is_equal(wi_array(), wi_dictionary()), "");
    WI_TEST_ASSERT_NULL(wi_description(NULL), "");
    WI_TEST_ASSERT_EQUALS(wi_hash(NULL), 0U, "");
}
예제 #3
0
wi_dictionary_t * wi_sqlite3_fetch_statement_results(wi_sqlite3_database_t *database, wi_sqlite3_statement_t *statement) {
	wi_mutable_dictionary_t		*results;
	wi_runtime_instance_t		*instance;
	int							i, count, length, result;
	
	wi_recursive_lock_lock(database->lock);
	
	result = sqlite3_step(statement->statement);
	
	switch(result) {
		case SQLITE_DONE:
			results = wi_dictionary();

			sqlite3_finalize(statement->statement);
			statement->statement = NULL;
			break;
			
		case SQLITE_ROW:
			results			= wi_mutable_dictionary();
			count			= sqlite3_column_count(statement->statement);
			
			for(i = 0; i < count; i++) {
				switch(sqlite3_column_type(statement->statement, i)) {
					case SQLITE_INTEGER:
						instance	= wi_number_with_int64(sqlite3_column_int64(statement->statement, i));
						break;
						
					case SQLITE_FLOAT:
						instance	= wi_number_with_double(sqlite3_column_double(statement->statement, i));
						break;
						
					case SQLITE_TEXT:
						instance	= wi_string_with_cstring((const char *) sqlite3_column_text(statement->statement, i));
						break;
						
					case SQLITE_BLOB:
						length		= sqlite3_column_bytes(statement->statement, i);
						instance	= wi_data_with_bytes(sqlite3_column_blob(statement->statement, i), length);
						break;
						
					case SQLITE_NULL:
						instance	= wi_null();
						break;
					
					default:
						instance	= NULL;
						break;
				}
				
				if(instance)
					wi_mutable_dictionary_set_data_for_key(results, instance, wi_string_with_cstring(sqlite3_column_name(statement->statement, i)));
			}
	
			wi_runtime_make_immutable(results);
			break;
			
		default:
			wi_error_set_sqlite3_error_with_description(database->database, wi_description(statement));

			sqlite3_finalize(statement->statement);
			statement->statement = NULL;

			results = NULL;
			break;
	}
	
	wi_recursive_lock_unlock(database->lock);
		
	return results;
}