Beispiel #1
0
void test_zeroMatchFlags (void)
{
	Key * parentKey = keyNew ("user/tests/glob", KEY_END);
	KeySet * conf = ksNew (20, keyNew ("user/glob/#1", KEY_VALUE, "*test1", KEY_META, "testmetakey1", "testvalue1", KEY_END),
			       /* disable default pathname globbing behaviour */
			       keyNew ("user/glob/#1/flags", KEY_VALUE, "", KEY_END), KS_END);
	PLUGIN_OPEN ("glob");

	KeySet * ks = createKeys ();

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (output_error (parentKey), "error in kdbSet");
	succeed_if (output_warnings (parentKey), "warnings in kdbSet");


	Key * key = ksLookupByName (ks, "user/tests/glob/test1", 0);
	exit_if_fail (key, "key user/tests/glob/test1 not found");
	const Key * metaKey1 = keyGetMeta (key, "testmetakey1");
	exit_if_fail (metaKey1, "testmetakey1 not found");
	succeed_if (strcmp ("testvalue1", keyValue (metaKey1)) == 0, "value of metakey testmetakey1 not correct");

	key = ksLookupByName (ks, "user/tests/glob/test3", 0);
	exit_if_fail (key, "user/tests/glob/test3 not found");
	succeed_if (!keyGetMeta (key, "testmetakey1"), "testmetakey1 copied to wrong key");

	key = ksLookupByName (ks, "user/tests/glob/test2/subtest1", 0);
	exit_if_fail (key, "user/tests/glob/test2/subtest1 not found");
	const Key * metaKey2 = keyGetMeta (key, "testmetakey1");
	exit_if_fail (metaKey2, "testmetakey1 not found");
	succeed_if (strcmp ("testvalue1", keyValue (metaKey2)) == 0, "value of metakey testmetakey1 not correct");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
Beispiel #2
0
void test_setGlobalMatch (void)
{
	Key * parentKey = keyNew ("user/tests/glob", KEY_END);
	// clang-format off
	KeySet *conf = ksNew (20,
			keyNew ("user/glob/#1", KEY_VALUE, "/*",
					KEY_META, "testmetakey1", "testvalue1",
					KEY_META, "testmetakey2", "testvalue2",
					KEY_END),
			KS_END);
	// clang-format on
	PLUGIN_OPEN ("glob");

	KeySet * ks = createKeys ();

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (output_error (parentKey), "error in kdbSet");
	succeed_if (output_warnings (parentKey), "warnings in kdbSet");

	testKeys (ks);
	ksDel (ks);
	keyDel (parentKey);

	PLUGIN_CLOSE ();
}
Beispiel #3
0
void test_namedMatchFlags (void)
{
	Key * parentKey = keyNew ("user/tests/glob", KEY_END);
	KeySet * conf = ksNew (20, keyNew ("user/glob/#1", KEY_VALUE, "user/tests/glob/*", KEY_META, "testmetakey1", "testvalue1", KEY_END),
			       /* explicitly request pathname matching */
			       keyNew ("user/glob/#1/flags", KEY_VALUE, "pathname", KEY_END), KS_END);
	PLUGIN_OPEN ("glob");

	KeySet * ks = createKeys ();

	succeed_if (plugin->kdbSet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (output_error (parentKey), "error in kdbSet");
	succeed_if (output_warnings (parentKey), "warnings in kdbSet");

	Key * key = ksLookupByName (ks, "user/tests/glob/test1", 0);
	exit_if_fail (key, "key user/tests/glob/test1 not found");
	const Key * metaKey1 = keyGetMeta (key, "testmetakey1");
	exit_if_fail (metaKey1, "testmetakey1 not found");

	key = ksLookupByName (ks, "user/tests/glob/test3", 0);
	exit_if_fail (key, "user/tests/glob/test3 not found");
	const Key * metaKey2 = keyGetMeta (key, "testmetakey1");
	exit_if_fail (metaKey2, "testmetakey1 not found");

	key = ksLookupByName (ks, "user/tests/glob/test2/subtest1", 0);
	exit_if_fail (key, "user/tests/glob/test2/subtest1 not found");
	const Key * metaKey3 = keyGetMeta (key, "testmetakey1");
	exit_if_fail (!metaKey3, "testmetakey1 was copied to subtest1, but subtest1 should not be matched with pathname flag");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
bool PianoKeyBoard::init()
{
    //1.enable the touch event...
    
    //2.
    lowNote_ = 48 ;
    highNote_ = 83 ;
    
    keys_ =new Dictionary();
   
    whiteNormalPix_="game-keyboard-white.png";
    whiteDownPix_="game-keyboard-white-p.png";
    whiteErrorPix_="game-keyboard-white-pw.png";
    blackNormalPix_="game-keyboard-black.png";
    blackDownPix_="game-keyboard-black-p.png";
    blackErrorPix_="game-keyboard-black-pw.png";
    
    
    keyboardSize_ = (this->getBoundingBox()).size ;
    calculateKeySize(keyboardSize_);
    
    createKeys();
    
    drawKeyBoard();
    
    return true ;
}
Beispiel #5
0
void test_onlyFirstMatchIsApplied (void)
{
	Key * parentKey = keyNew ("user/tests/glob", KEY_END);
	// clang-format off
	KeySet * conf = ksNew (20,
				keyNew ("user/glob/#1",
						KEY_VALUE, "user/tests/glob/test1*",
						KEY_META, "testmetakey1", "testvalue1",
						KEY_END),
				keyNew ("user/glob/#2",
						KEY_VALUE, "user/tests/glob/*",
						KEY_META, "testmetakey2", "testvalue2",
						KEY_END),
			       /* disable all flags */
			    keyNew ("user/glob/#1/flags",
			    		KEY_VALUE, "",
						KEY_END),
				keyNew ("user/glob/#2/flags",
				   		KEY_VALUE, "",
						KEY_END),
				KS_END);
	// clang-format on
	PLUGIN_OPEN ("glob");

	KeySet * ks = createKeys ();

	succeed_if (plugin->kdbGet (plugin, ks, parentKey) >= 1, "call to kdbSet was not successful");
	succeed_if (output_error (parentKey), "error in kdbSet");
	succeed_if (output_warnings (parentKey), "warnings in kdbSet");

	Key * key = ksLookupByName (ks, "user/tests/glob/test1", 0);
	exit_if_fail (key, "key user/tests/glob/test1 not found");
	const Key * firstMatchKey = keyGetMeta (key, "testmetakey1");
	exit_if_fail (firstMatchKey, "testmetakey1 not found");
	const Key * secondMatchKey = keyGetMeta (key, "testmetakey2");
	exit_if_fail (!secondMatchKey, "testmetakey2 was applied to testmetakey1 although another match was already applied")

		key = ksLookupByName (ks, "user/tests/glob/test2/subtest1", 0);
	exit_if_fail (key, "user/tests/glob/test2/subtest1 not found");
	exit_if_fail (keyGetMeta (key, "testmetakey2"), "testmetakey2 not found");

	key = ksLookupByName (ks, "user/tests/glob/test3", 0);
	exit_if_fail (key, "user/tests/glob/test3 not found");
	exit_if_fail (keyGetMeta (key, "testmetakey2"), "testmetakey2 not found");

	ksDel (ks);
	keyDel (parentKey);
	PLUGIN_CLOSE ();
}
TEST_F(ProtectKeyHaspSLTest, find_key) {
	protect_keys_t protect_keys = createKeys();
	auto iprotectKey = ProtectKey::find_key(protect_keys, nullptr);
}
Beispiel #7
0
int
main(int argc,char **argv)
{
	char *program = argv[0];

	while (*++argv)
	{
		char *arg = *argv;
		if (*arg == '-')
		{
			if (arg[1] == '-')
				usage(program);

			while (*++arg && isalpha(*arg))
			{
				switch (*arg)
				{
					case 'v':
						gVerbose = true;
						break;
					case 'e':
						gExcessive = true;
						break;
					case 't':
						if (*++argv == NULL)
							usage(program);

						if (!strcmp(*argv,"string"))
							gType = S_STR_INDEX;
						else if (!strcmp(*argv,"int32")
							|| !strcmp(*argv,"int"))
							gType = S_INT_INDEX;
						else if (!strcmp(*argv,"uint32")
							|| !strcmp(*argv,"uint"))
							gType = S_UINT_INDEX;
						else if (!strcmp(*argv,"int64")
							|| !strcmp(*argv,"llong"))
							gType = S_LONG_LONG_INDEX;
						else if (!strcmp(*argv,"uint64")
							|| !strcmp(*argv,"ullong"))
							gType = S_ULONG_LONG_INDEX;
						else if (!strcmp(*argv,"float"))
							gType = S_FLOAT_INDEX;
						else if (!strcmp(*argv,"double"))
							gType = S_DOUBLE_INDEX;
						else
							usage(program);
						break;
					case 'n':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);
						
						gNum = atoi(*argv);
						if (gNum < 1)
							gNum = 1;
						break;
					case 'h':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);

						gHard = atoi(*argv);
						if (gHard < 1)
							gHard = 1;
						break;
					case 'i':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);

						gIterations = atoi(*argv);
						if (gIterations < 1)
							gIterations = 1;
						break;
					case 'r':
						if (*++argv == NULL || !isdigit(**argv))
							usage(program);
						
						gSeed = atoi(*argv);
						break;
				}
			}
		}
		else
			break;
	}

	// we do want to have reproducible random keys
	if (gVerbose)
		printf("Set seed to %ld\n",gSeed);
	srand(gSeed);
	
	Inode inode("tree.data",gType | S_ALLOW_DUPS);
	gVolume = inode.GetVolume();
	Transaction transaction(gVolume,0);

	init_cache(gVolume->Device(),gVolume->BlockSize());

	//
	// Create the tree, the keys, and add all keys to the tree initially
	//

	BPlusTree tree(&transaction,&inode);
	status_t status;
	if ((status = tree.InitCheck()) < B_OK) {
		fprintf(stderr,"creating tree failed: %s\n",strerror(status));
		bailOut();
	}
	printf("*** Creating %ld keys...\n",gNum);
	if ((status = createKeys()) < B_OK) {
		fprintf(stderr,"creating keys failed: %s\n",strerror(status));
		bailOut();
	}

	if (gVerbose)
		dumpKeys();

	for (int32 j = 0; j < gHard; j++ ) {
		addAllKeys(&transaction, &tree);

		//
		// Run the tests (they will exit the app, if an error occurs)
		//
	
		for (int32 i = 0;i < gIterations;i++) {
			printf("---------- Test iteration %ld ---------------------------------\n",i+1);
	
			addRandomSet(&transaction,&tree,int32(1.0 * gNum * rand() / RAND_MAX));
			removeRandomSet(&transaction,&tree,int32(1.0 * gNum * rand() / RAND_MAX));
			duplicateTest(&transaction,&tree);
		}
	
		removeAllKeys(&transaction, &tree);
	}

	// of course, we would have to free all our memory in a real application here...

	// write the cache back to the tree
	shutdown_cache(gVolume->Device(),gVolume->BlockSize());
	return 0;
}