Exemple #1
0
void
do_give(int descr, dbref player, const char *recipient, int amount)
{
	dbref who;
	char buf[BUFFER_LEN];
	struct match_data md;

	/* do amount consistency check */
	if (amount < 0 && !Wizard(OWNER(player))) {
		notify(player, "Try using the \"rob\" command.");
		return;
	} else if (amount == 0) {
		notify_fmt(player, "You must specify a positive number of %s.", tp_pennies);
		return;
	}
	/* check recipient */
	init_match(descr, player, recipient, TYPE_PLAYER, &md);
	match_neighbor(&md);
	match_me(&md);
	if (Wizard(OWNER(player))) {
		match_player(&md);
		match_absolute(&md);
	}
	switch (who = match_result(&md)) {
	case NOTHING:
		notify(player, "Give to whom?");
		return;
	case AMBIGUOUS:
		notify(player, "I don't know who you mean!");
		return;
	default:
		if (!Wizard(OWNER(player))) {
			if (Typeof(who) != TYPE_PLAYER) {
				notify(player, "You can only give to other players.");
				return;
			} else if (GETVALUE(who) + amount > tp_max_pennies) {
				notify_fmt(player, "That player doesn't need that many %s!", tp_pennies);
				return;
			}
		}
		break;
	}

	/* try to do the give */
	if (!payfor(player, amount)) {
		notify_fmt(player, "You don't have that many %s to give!", tp_pennies);
	} else {
		/* he can do it */
		switch (Typeof(who)) {
		case TYPE_PLAYER:
			SETVALUE(who, GETVALUE(who) + amount);
			if(amount >= 0) {
				snprintf(buf, sizeof(buf), "You give %d %s to %s.",
						amount, amount == 1 ? tp_penny : tp_pennies, NAME(who));
				notify(player, buf);
				snprintf(buf, sizeof(buf), "%s gives you %d %s.",
						NAME(player), amount, amount == 1 ? tp_penny : tp_pennies);
				notify(who, buf);
			} else {
				snprintf(buf, sizeof(buf), "You take %d %s from %s.",
						-amount, amount == -1 ? tp_penny : tp_pennies, NAME(who));
				notify(player, buf);
				snprintf(buf, sizeof(buf), "%s takes %d %s from you!",
						NAME(player), -amount, -amount == 1 ? tp_penny : tp_pennies);
				notify(who, buf);
			}
			break;
		case TYPE_THING:
			SETVALUE(who, (GETVALUE(who) + amount));
			snprintf(buf, sizeof(buf), "You change the value of %s to %d %s.",
					NAME(who),
					GETVALUE(who), GETVALUE(who) == 1 ? tp_penny : tp_pennies);
			notify(player, buf);
			break;
		default:
			notify_fmt(player, "You can't give %s to that!", tp_pennies);
			break;
		}
		DBDIRTY(who);
	}
}
Exemple #2
0
void
do_kill(int descr, dbref player, const char *what, int cost)
{
	dbref victim;
	char buf[BUFFER_LEN];
	struct match_data md;

	init_match(descr, player, what, TYPE_PLAYER, &md);
	match_neighbor(&md);
	match_me(&md);
	if (Wizard(OWNER(player))) {
		match_player(&md);
		match_absolute(&md);
	}
	victim = match_result(&md);

	switch (victim) {
	case NOTHING:
		notify(player, "I don't see that player here.");
		break;
	case AMBIGUOUS:
		notify(player, "I don't know who you mean!");
		break;
	default:
		if (Typeof(victim) != TYPE_PLAYER) {
			notify(player, "Sorry, you can only kill other players.");
		} else {
			/* go for it */
			/* set cost */
			if (cost < tp_kill_min_cost)
				cost = tp_kill_min_cost;

			if (FLAGS(DBFETCH(player)->location) & HAVEN) {
				notify(player, "You can't kill anyone here!");
				break;
			}

			if (tp_restrict_kill) {
				if (!(FLAGS(player) & KILL_OK)) {
					notify(player, "You have to be set Kill_OK to kill someone.");
					break;
				}
				if (!(FLAGS(victim) & KILL_OK)) {
					notify(player, "They don't want to be killed.");
					break;
				}
			}

			/* see if it works */
			if (!payfor(player, cost)) {
				notify_fmt(player, "You don't have enough %s.", tp_pennies);
			} else if ((RANDOM() % tp_kill_base_cost) < cost && !Wizard(OWNER(victim))) {
				/* you killed him */
				if (GETDROP(victim))
					/* give him the drop message */
					notify(player, GETDROP(victim));
				else {
					snprintf(buf, sizeof(buf), "You killed %s!", NAME(victim));
					notify(player, buf);
				}

				/* now notify everybody else */
				if (GETODROP(victim)) {
					snprintf(buf, sizeof(buf), "%s killed %s! ", NAME(player), NAME(victim));
					parse_oprop(descr, player, getloc(player), victim,
								   MESGPROP_ODROP, buf, "(@Odrop)");
				} else {
					snprintf(buf, sizeof(buf), "%s killed %s!", NAME(player), NAME(victim));
				}
				notify_except(DBFETCH(DBFETCH(player)->location)->contents, player, buf,
							  player);

				/* maybe pay off the bonus */
				if (GETVALUE(victim) < tp_max_pennies) {
					snprintf(buf, sizeof(buf), "Your insurance policy pays %d %s.",
							tp_kill_bonus, tp_pennies);
					notify(victim, buf);
					SETVALUE(victim, GETVALUE(victim) + tp_kill_bonus);
					DBDIRTY(victim);
				} else {
					notify(victim, "Your insurance policy has been revoked.");
				}
				/* send him home */
				send_home(descr, victim, 1);

			} else {
				/* notify player and victim only */
				notify(player, "Your murder attempt failed.");
				snprintf(buf, sizeof(buf), "%s tried to kill you!", NAME(player));
				notify(victim, buf);
			}
			break;
		}
	}
}
Exemple #3
0
void
do_toad(int descr, dbref player, const char *name, const char *recip)
{
	dbref victim;
	dbref recipient;
	dbref stuff;
	char buf[BUFFER_LEN];

	if (!Wizard(player) || Typeof(player) != TYPE_PLAYER) {
		notify(player, "Only a Wizard player can turn a person into a toad.");
		return;
	}
	if ((victim = lookup_player(name)) == NOTHING) {
		notify(player, "That player does not exist.");
		return;
	}
#ifdef GOD_PRIV
	if (God(victim)) {
		notify(player, "You cannot @toad God.");
		if(!God(player)) {
			log_status("TOAD ATTEMPT: %s(#%d) tried to toad God.",NAME(player),player);
		}
		return;
	}
#endif
	if(player == victim) {
		/* If GOD_PRIV isn't defined, this could happen: we don't want the
		 * last wizard to be toaded, in any case, so only someone else can
		 * do it. */
		notify(player, "You cannot toad yourself.  Get someone else to do it for you.");
		return;
	}

	if (victim == tp_toad_default_recipient) {
		notify(player, "That player is part of the @toad process, and cannot be deleted.");
		return;
	}

	if (!*recip) {
		recipient = tp_toad_default_recipient;
	} else {
		if ((recipient = lookup_player(recip)) == NOTHING || recipient == victim) {
			notify(player, "That recipient does not exist.");
			return;
		}
	}

	if (Typeof(victim) != TYPE_PLAYER) {
		notify(player, "You can only turn players into toads!");
#ifdef GOD_PRIV
	} else if (!(God(player)) && (TrueWizard(victim))) {
#else
	} else if (TrueWizard(victim)) {
#endif
		notify(player, "You can't turn a Wizard into a toad.");
	} else {
		/* we're ok */
		/* do it */
		send_contents(descr, victim, HOME);
		dequeue_prog(victim, 0);  /* Dequeue the programs that the player's running */
		for (stuff = 0; stuff < db_top; stuff++) {
			if (OWNER(stuff) == victim) {
				switch (Typeof(stuff)) {
				case TYPE_PROGRAM:
					dequeue_prog(stuff, 0);	/* dequeue player's progs */
					if (TrueWizard(recipient)) {
						FLAGS(stuff) &= ~(ABODE | WIZARD);
						SetMLevel(stuff, 1);
					}
				case TYPE_ROOM:
				case TYPE_THING:
				case TYPE_EXIT:
					OWNER(stuff) = recipient;
					DBDIRTY(stuff);
					break;
				}
			}
			if (Typeof(stuff) == TYPE_THING && THING_HOME(stuff) == victim) {
				THING_SET_HOME(stuff, tp_lost_and_found);
			}
		}

		chown_macros(victim, recipient);

		if (PLAYER_PASSWORD(victim)) {
			free((void *) PLAYER_PASSWORD(victim));
			PLAYER_SET_PASSWORD(victim, 0);
		}

		/* notify people */
		notify(victim, "You have been turned into a toad.");
		snprintf(buf, sizeof(buf), "You turned %s into a toad!", NAME(victim));
		notify(player, buf);
		log_status("TOADED: %s(%d) by %s(%d)", NAME(victim), victim, NAME(player), player);
		/* reset name */
		delete_player(victim);
		snprintf(buf, sizeof(buf), "A slimy toad named %s", NAME(victim));
		free((void *) NAME(victim));
		NAME(victim) = alloc_string(buf);
		DBDIRTY(victim);

		boot_player_off(victim); /* Disconnect the toad */

		if (PLAYER_DESCRS(victim)) {
			free(PLAYER_DESCRS(victim));
			PLAYER_SET_DESCRS(victim, NULL);
			PLAYER_SET_DESCRCOUNT(victim, 0);
		}

		ignore_remove_from_all_players(victim);
		ignore_flush_cache(victim);

		FREE_PLAYER_SP(victim);
		ALLOC_THING_SP(victim);
		THING_SET_HOME(victim, PLAYER_HOME(player));

		FLAGS(victim) = TYPE_THING;
		OWNER(victim) = player;	/* you get it */
		SETVALUE(victim, 1);	/* don't let him keep his immense wealth */
	}
}
Exemple #4
0
bool config_setLocation( int argc, const char *argv[], void *data )
{
    #define configSetLocation_RouteId       0
    #define configSetLocation_StopId        1
    #define configSetLocation_EntryPointId  2
    #define configSetLocation_Unavailable   3

    const char             *rtId            = argv[ configSetLocation_RouteId ];
    const char             *stopId          = argv[ configSetLocation_StopId  ];
    const char             *epId            = argc >= ( configSetLocation_EntryPointId + 1 ) ? argv[ configSetLocation_EntryPointId ] : NULL;
    const char             *locUnav         = argc >= ( configSetLocation_Unavailable  + 1 ) ? argv[ configSetLocation_Unavailable  ] : NULL;
    bool                    ret             = false;
    unsigned long           id              = 0;
    char                    waste           = 0;
    MYKI_BR_ContextData_t  *pContextData    = GetCardProcessingThreadContextData();
    IPC_IntPayload_t        ipcSetLocation;
    int                     nLineId         = pContextData->DynamicData.lineId;
    int                     nStopId         = pContextData->DynamicData.stopId;
    int                     nEntryPointId   = pContextData->DynamicData.entryPointId;
    bool                    locAvailable    = true;
    int                     nResult         = 0;
    int                     AppQueueId      = IpcGetID( APP_TASK );

    CsDebug( 9, ( 9, "Set location to %s, %s, %s, %s",
        ( rtId    == NULL ? "(null)" : rtId    ),
        ( stopId  == NULL ? "(null)" : stopId  ),
        ( epId    == NULL ? "(null)" : epId    ),
        ( locUnav == NULL ? "(null)" : locUnav ) ) );

    memset( &ipcSetLocation, 0, sizeof( ipcSetLocation ) );

#define SETVALUE(INPUT, OUTPUT, MAXVALUE, DESC) \
    if ( INPUT != 0 && INPUT[0] != '-' ) \
    { \
        if ( sscanf(INPUT, "%ld%c", &id, &waste) != 1 || id > (unsigned long)(MAXVALUE) ) \
        { \
            CsDebug(9, (9, "Invalid %s '%s'", DESC, INPUT)); \
        } \
        else \
        { \
            OUTPUT = id; \
            CsDebug(9, (9, "Successfully set %s to '%s', %d", DESC, INPUT, int(OUTPUT))); \
            ret = true; \
        } \
    } \
    else \
    { \
        CsDebug(9, (9, "Default %s is %d", DESC, (int)OUTPUT)); \
    }
    SETVALUE( rtId,   nLineId,       0xffff,     "route ID"       );
    SETVALUE( stopId, nStopId,       0xff,       "stop ID"        );
    SETVALUE( epId,   nEntryPointId, 0x7fffffff, "entry point ID" );
#undef SETVALUE

    if ( ret == true )
    {
        pContextData->DynamicData.entryPointId  = nEntryPointId;

        if ( locUnav != NULL )
        {
            locAvailable   =
                ( 
                    locUnav[ 0 ] == 't' || locUnav[ 0 ] == 'T' ||   /*  [Tt]rue */
                    locUnav[ 0 ] == 'y' || locUnav[ 0 ] == 'Y' ||   /*  [Yy]es */
                    locUnav[ 0 ] == '1'
                )   ? false : true;
        }

        ipcSetLocation.hdr.type     = IPC_SET_LOCATION;
        ipcSetLocation.hdr.source   = APP_TASK;
        ipcSetLocation.data         = (   nLineId               & 0x0000ffff ) |
                                      ( ( nStopId << 16 )       & 0x00ff0000 ) |
                                      ( ( locAvailable != false ? 0x80000000 : 0x00000000 ) );

        if ( ( nResult = IpcSend( AppQueueId, &ipcSetLocation, sizeof( ipcSetLocation ) ) ) != 0 )
        {
            CsErrx( "config_setLocation : IpcSend failed (%d)", nResult );
            ret = false;
        }
    }

    return ret;
}
int TestRefVal::execute()
{
	bool lSuccess = true;
	if (MVTApp::startStore())
	{
		ISession * const lSession =	MVTApp::startSession();
		const static int lNumProps = 25;
		PropertyID lPropIDs[lNumProps];
		MVTApp::mapURIs(lSession,"TestRefVal.prop",lNumProps,lPropIDs);

		// Create a few pins with properties, collections,
		// and references to other properties or values.
		typedef std::set<StoreReference, SortByReferenced> TReferences;
		TReferences lReferences;
		int i, j, k;
		PID lPIDs[100];
		for (i = 0; i < 100; i++)
		{
			CREATEPIN(lSession, &lPIDs[i], NULL, 0);
			IPIN * const lPIN = lSession->getPIN(lPIDs[i]);
			int const lNumProps = MVTRand::getRange(1, 20);
			for (j = 0; j < lNumProps; j++)
			{
				int const lNumVals = MVTRand::getRange(1, 5);
				for (k = 0; k < lNumVals; k++)
				{
					bool lDoReference = i > 0 && MVTRand::getRange(0, 10) > 3;

					// Either create a reference to some other property/value created earlier...
					if (lDoReference)
					{
						StoreReference lReference;
						lReference.mReferencing.id = lPIDs[i];
						lReference.mReferencing.pid = lPropIDs[j];
						lReference.mReferencing.eid = 0;

						// Choose a PIN to reference.
						int const lPINReferencedIndex = MVTRand::getRange(0, i-1);
						lReference.mReferenced.id = lPIDs[lPINReferencedIndex];

						// Choose a property to reference.
						IPIN * lPINReferenced;
						bool lOLMethod = MVTRand::getRange(0, 100) > 33;
						if(lOLMethod){
							lPINReferenced = lSession->getPIN(lReference.mReferenced.id);
						}
						else{
							Value lVal;
							lVal.set(lReference.mReferenced.id);
							lPINReferenced = lSession->getPIN(lVal);	
						}
						int lNumPINProps = (int)lPINReferenced->getNumberOfProperties();
						unsigned int const lPropReferencedIndex = (unsigned int)MVTRand::getRange(0, lNumPINProps-1);
						Value const * const lPropReferenced = lPINReferenced->getValue(lPropIDs[lPropReferencedIndex]);
						lReference.mReferenced.pid = lPropReferenced->property;

						// Choose a value to reference, if relevant.
						if (lPropReferenced->type == VT_COLLECTION && !lPropReferenced->isNav())
						{
							int const lValueReferencedIndex = MVTRand::getRange(0, (int)lPropReferenced->length-1);
							lReference.mReferenced.eid = lPropReferenced->varray[lValueReferencedIndex].eid;
						}
						else
						{
							lReference.mReferenced.eid = STORE_COLLECTION_ID;
							if(lPropReferenced->type == VT_COLLECTION) 
								TVERIFY(false && "navigator returned even after setting session interface mode to ITF_COLLECTIONS_AS_ARRAYS");
						}

						// Unless this exact same reference already exists, create it.
						if (lReferences.end() != lReferences.find(lReference))
							lDoReference = false;
						else
						{
							Value lPV;
							SETVALUE(lPV, lPropIDs[j], lReference.mReferenced, OP_ADD);
							if (RC_OK != lPIN->modify(&lPV, 1))
							{
								lSuccess = false;
								assert(false);
							}
							else
								lReferences.insert(lReference);
						}
					}

					// Or create a new property.
					if (!lDoReference)
					{
						Value lPV;
						Tstring lString;
						MVTRand::getString(lString, 20, 0, false);
						SETVALUE_C(lPV, lPropIDs[j], lString.c_str(), OP_ADD, STORE_LAST_ELEMENT);
						if (RC_OK != lPIN->modify(&lPV, 1))
						{
							#if 0
								lSuccess = false;
								assert(false);
							#endif
						}
					}
				}
			}
			lPIN->destroy();
		}

		#if 0 // Note: Queries for VT_REFIDELT not supported yet...
		// Query to see if all relationships are found.
		TReferences::iterator lItRef;
		for (lItRef = lReferences.begin(); lReferences.end() != lItRef; lItRef++)
		{
			// Execute the mvstore query.
			IStmt * const lQ = lSession->createStmt();
			unsigned char const lVar = lQ->addVariable();
			Value lV[2];
			PropertyID lPropIds[] = {(*lItRef).mReferencing.pid};
			lV[0].setVarRef(0, *lPropIds);
			lV[1].set((*lItRef).mReferenced);
			TExprTreePtr lExprTree = EXPRTREEGEN(lSession)(OP_EQ, 2, lV, 0);
			lQ->addCondition(lExprTree);
			ICursor * const lQR = lQ->execute();

			// Check that all objects found by the mvstore query are correct.
			IPIN * lQRIter;
			int lNumFound = 0;
			for (lQRIter = lQR->next(); NULL != lQRIter; lQRIter = lQR->next(), lNumFound++)
			{
				StoreReference lRef;
				lRef.mReferencing.id = lQRIter->getPID();
				lRef.mReferencing.pid = (*lItRef).mReferencing.pid;
				lRef.mReferenced = (*lItRef).mReferenced;
				if (lReferences.end() == lReferences.find(lRef))
				{
					lSuccess = false;
					mLogger.out() << "Query found a reference that did not exist!" << std::endl;
				}
			}

			// Check that the mvstore query found exactly the right number of objects.
			int lNumExpected = 0;
			TReferences::iterator lItRef2;
			StoreReference lRef;
			lRef.mReferenced = (*lItRef).mReferenced;
			INITLOCALPID(lRef.mReferencing.id);
			LOCALPID(lRef.mReferencing) = 0;
			lRef.mReferencing.pid = 0;
			lRef.mReferencing.eid = 0;
			for (lItRef2 = lReferences.lower_bound(lRef); lReferences.end() != lItRef2 && equalRefVIDs((*lItRef2).mReferenced, lRef.mReferenced); lItRef2++)
				if ((*lItRef2).mReferencing.pid == (*lItRef).mReferencing.pid)
					lNumExpected++;
			if (lNumFound != lNumExpected)
			{
				lSuccess = false;
				mLogger.out() << "Query found " << lNumFound << " referencing objects instead of " << lNumExpected << std::endl;
			}

			// Cleanup.
			lQR->destroy();
			lQ->destroy();
		}
		#endif

		lSession->terminate();
		MVTApp::stopStore();
	}
	else { TVERIFY(!"Unable to start store"); }
	return lSuccess	? 0	: 1;
}
// Implement this test.
int TestMergeCollections::execute()
{
	bool lSuccess =	true;
	if (MVTApp::startStore())
	{
		ISession * const lSession =	MVTApp::startSession();

		// Declare properties.
		URIMap	lData[2];
		MVTApp::mapURIs(lSession,"TestMergeCollections.prop",2,lData);
		PropertyID const lPropIdVal    = lData[0].uid;
		PropertyID const lPropIdRef    = lData[1].uid;
		PropertyID const lPropIdPinId  = PROP_SPEC_PINID;

		DataEventID lClassVal = STORE_INVALID_CLASSID;
		{
			char lB[100]; sprintf(lB,"TestMergeCollections.ClassVal.%d",rand());
			Value lV[2]; 
			lV[0].setVarRef(0,lPropIdVal);
			lV[1].setParam(0);
			IExprNode *expr=lSession->expr(OP_LT,2,lV);
			IStmt *lQ = lSession->createStmt();
			lQ->addVariable(NULL,0,expr);
			TVERIFYRC(defineClass(lSession,lB,lQ,&lClassVal));
			lQ->destroy();
		}

		DataEventID lClassRef = STORE_INVALID_CLASSID;
		{
			char lB[100]; sprintf(lB,"TestMergeCollections.ClassRef.%d",rand());
			IStmt *lQ = lSession->createStmt();
			lQ->addVariable();
			lQ->setPropCondition(0,&lPropIdRef,1);
			TVERIFYRC(defineClass(lSession,lB,lQ,&lClassRef));
			lQ->destroy();
		}

		/**
		* The following creates the family on reference class...
		**/		
		DataEventID lClassFamilyOnRef = STORE_INVALID_CLASSID;
		{
			char lB[100]; sprintf(lB,"TestMergeCollections.ClassFamilyOnRef.%d",rand());
			Value lVFoR[2];
			lVFoR[0].setVarRef(0,lPropIdRef);
			lVFoR[1].setParam(0);
			IExprNode *expr=lSession->expr(OP_IN,2,lVFoR);
			IStmt *lQ = lSession->createStmt();
			lQ->addVariable(NULL,0,expr);
			TVERIFYRC(defineClass(lSession,lB,lQ,&lClassFamilyOnRef));
			lQ->destroy();
		}

		// Create a few pins
		mLogger.out() << "Creating " << NPINS*2 << " pins... ";

		PID pins[NPINS]; bool lfMember[NPINS];
		PID refferedPins[NPINS];

		//Creating first group of pins: 
		// - each pin may have an interger value, or collection of interger values; 
		// - each pin may have the same interger value within collection; 
		// - if at least one of the values within pin < treshold, it should be picked up by the family... 		
		const int threshold = RANGE/3; int i;
		if(isVerbose()) mLogger.out() << " List of PINs with value less than threshold " << std::endl;
		for (i = 0; i < NPINS; i++)
		{
			Value lV[2]; 
			int val = MVTRand::getRange(0, RANGE);
			lfMember[i] = val < threshold;
			SETVALUE(lV[0], lPropIdVal, val, OP_SET);
			CREATEPIN(lSession, &pins[i], lV, 1);
                        
			IPIN *ppin = lSession->getPIN(pins[i]);
			int elemincollection = MVTRand::getRange(1, MAX_ELEM_INCOLLECTION);
			for(int jj = 0; jj < elemincollection; jj++)
			{
				int val2 = MVTRand::getRange(1, RANGE);
				if(!lfMember[i] && (val2 < threshold)) 
					lfMember[i] = true;
				SETVALUE_C(lV[0], lPropIdVal, val2, OP_ADD, STORE_LAST_ELEMENT);
				TVERIFYRC(ppin->modify(lV,1));
			}
			if(isVerbose() && lfMember[i]) mLogger.out() << std::hex <<  pins[i].pid << std::endl;
			ppin->destroy();
		}

		// Create second group of pins:
		//  - each pin within that group has either reference or collection of references 
		//    to a random pin(s) in the set above
		//  - the reference to the pin, which value < threshold may be within any position within collection; 
		//  - it may be multiple references to the same pin, including the pin which value < threshold; 		
		if(isVerbose()) mLogger.out() << " List of PINs with refs whose value is less than threshold " << std::endl;
		int lCount = 0; 
		int lCountDiff = 0; //counts how many pins with value < threshold has been added while creating collection... 
		for (i = 0; i < NPINS; i++)
		{
			PID lReferPID;
			INITLOCALPID(lReferPID); lReferPID.pid = STORE_INVALID_PID;
			Value lV[2]; 
			int idx = MVTRand::getRange(0, NPINS-1); 
			PID id; bool willbefound = false;
			if (lfMember[idx])
			{ 
				lCount++; 
				willbefound = true; // The referenced pin will match the family query
				lReferPID = pins[idx];
			} 
			SETVALUE(lV[0], lPropIdRef, pins[idx], OP_SET); 
			refferedPins[i] = pins[idx];    // to remember reffered pins;
			CREATEPIN(lSession, &id, lV, 1);

			IPIN *ppin = lSession->getPIN(id);
			int elemincollection = MVTRand::getRange(1, MAX_ELEM_INCOLLECTION);
			for(int jj = 0; jj < elemincollection; jj++)
			{
				int idx1 = MVTRand::getRange(0, NPINS-1);
				SETVALUE_C(lV[0], lPropIdRef, pins[idx1], OP_ADD, STORE_LAST_ELEMENT); 
				TVERIFYRC(ppin->modify(lV,1));

				if(!willbefound && lfMember[idx1])
				{ 
					lCount++; willbefound = true; 
					lReferPID = pins[idx1];
					lCountDiff++; 
				}  
			}
			if(isVerbose() && willbefound) mLogger.out() << std::hex << id.pid << " with ref to " << lReferPID.pid << std::endl;
			ppin->destroy();
		}
		
		mLogger.out() << std::dec << "DONE" << std::endl;
		
		// Do a simple join search.
		// " All pins from lClassFamilyOnRef Family, where any of the PINs in lPropIdRef has (lPropIdVal < threshhold)
		
		// "All pins, from lClassRef class, where the lPropIdRef property is equal 
		// to the PROP_SPEC_PINID of a PIN matching the lClassVal query of (lPropIdVal < threshhold)"
		// 
		IStmt *lQ	= lSession->createStmt();
		
		Value lV[4]; 
		lV[0].setError(lPropIdRef); lV[1].setError(lPropIdRef); lV[2].setRange(&lV[0]);
		lV[3].set(threshold); // Family query will find all pins with lPropIdVal < threshhold

		SourceSpec classSpec[2]={{lClassFamilyOnRef,1,&lV[2]},{lClassVal,1,&lV[3]}};		
		unsigned char lVar1 = lQ->addVariable(&classSpec[0],1),lVar2 = lQ->addVariable(&classSpec[1],1);

		lV[0].setVarRef(lVar1,lPropIdRef);
		lV[1].setVarRef(lVar2,lPropIdPinId);
		IExprNode *expr = lSession->expr(OP_EQ,2,lV);
		lQ->join(lVar1,lVar2,expr);
		OrderSeg ord={NULL,lPropIdRef,0,0,0};
		lQ->setOrder(&ord,1);

		uint64_t lCnt = 0;
		TVERIFYRC(lQ->count(lCnt,NULL,0,~0u));

		TVERIFY((int)lCnt == lCount);
		
		{
			mLogger.out() << "Count returned = " << lCnt << ";  Expected Count = " << lCount << "; lCountDiff = " << lCountDiff << ";" <<  std::endl;

			//The query below - attempt to find how many pins with at least one value < threshold were found by Family...
			mLogger.out() << "The query below - attempt to find how many pins with at least one value < threshold were found by Family..." << std::endl; 
			IStmt *lQFamily = lSession->createStmt(); 
			lQFamily->addVariable(&classSpec[1],1);
			uint64_t lCntFFound = 0;
			TVERIFYRC(lQFamily->count(lCntFFound));
			mLogger.out() << "lCntFFound= " << lCntFFound << ";" << std::endl;
			lQFamily->destroy();
		}  
		
		ICursor *lR = NULL;
		TVERIFYRC(lQ->execute(&lR, NULL,0,~0u,0));
		int lResultCount = 0;
		IPIN *pInResults;
		if (isVerbose()) mLogger.out() << "List of PINs returned " << std::endl;
		while((pInResults=lR->next())!=NULL)
		{
			lResultCount++;
			//if (isVerbose()) MVTApp::output(*pInResults,mLogger.out());
			if (isVerbose()) mLogger.out() << std::hex << pInResults->getPID().pid << std::endl;
			
			const Value * refVal = pInResults->getValue(lPropIdRef); 
			if ( refVal!=NULL )
			{
				MvStoreEx::CollectionIterator lCollection(refVal);
				bool lBelongs = false;
				const Value *lValue;
				for(lValue = lCollection.getFirst(); lValue!=NULL; lValue = lCollection.getNext())
				{
					TVERIFY(lValue->type == VT_REFID);
					IPIN *lPIN = lSession->getPIN(lValue->id); TVERIFY(lPIN != NULL);
					const Value *lVal = lPIN->getValue(lPropIdVal); 
					MvStoreEx::CollectionIterator lValues(lVal);
					const Value *lVal1;
					for(lVal1 = lValues.getFirst(); lVal1!=NULL; lVal1 = lValues.getNext())
					{
						TVERIFY(lVal1->type == VT_INT);
						if(lVal1->i < threshold)
						{ lBelongs = true; break; }
					}
					lPIN->destroy();
					if(lBelongs) break;
				}
				TVERIFY(lBelongs && "Unexpected PIN returned");
			}
			else
			{
				TVERIFY(false && "Failed to fetch the collection");
			}

			pInResults->destroy();
		}

		mLogger.out() << " Total PINs returned in the result set " << std::dec << lResultCount << std::endl;
		TVERIFY(lResultCount == lCount);

		lR->destroy();
		lQ->destroy();

		lSession->terminate();
		MVTApp::stopStore();
	}
	else { TVERIFY(!"could not open store") ; }

	return lSuccess ? 0 : 1;
}
Exemple #7
0
static int Set(advanced* p, int No, const void* Data, int Size)
{
	int Result = ERR_INVALID_PARAM;

	switch (No)
	{
	case ADVANCED_OLDSHELL: SETVALUE(p->OldShell,bool_t,ERR_NONE); break;
	case ADVANCED_HOMESCREEN: SETVALUE(p->HomeScreen,bool_t,ERR_NONE); break;
	case ADVANCED_NOBACKLIGHT: SETVALUE(p->NoBackLight,bool_t,ERR_NONE); break;
	case ADVANCED_VR41XX: SETVALUE(p->VR41XX,bool_t,ERR_NONE); break;
	case ADVANCED_IDCTSWAP: SETVALUECMP(p->IDCTSwap,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_NOWMMX: SETVALUE(p->NoWMMX,bool_t,ERR_NONE); break;
	case ADVANCED_BLINKLED: SETVALUE(p->BlinkLED,bool_t,ERR_NONE); break;
	case ADVANCED_NODEBLOCKING: SETVALUECMP(p->NoDeblocking,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_PRIORITY: SETVALUECMP(p->Priority,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_SYSTEMVOLUME: SETVALUECMP(p->SystemVolume,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_SLOW_VIDEO: SETVALUECMP(p->SlowVideo,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_COLOR_LOOKUP: SETVALUECMP(p->ColorLookup,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_DROPTOL: SETVALUECMP(p->DropTolerance,tick_t,NodeSettingsChanged(),EqInt); break;
	case ADVANCED_SKIPTOL: SETVALUECMP(p->SkipTolerance,tick_t,NodeSettingsChanged(),EqInt); break;
	case ADVANCED_AVOFFSET: SETVALUECMP(p->AVOffset,tick_t,NodeSettingsChanged(),EqInt); break;
	case ADVANCED_BENCHFROMPOS: SETVALUE(p->BenchFromPos,bool_t,ERR_NONE); break;
	case ADVANCED_AVIFRAMERATE: SETVALUECMP(p->AviFrameRate,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_WIDCOMMAUDIO: SETVALUE(p->WidcommAudio,bool_t,ERR_NONE); break;
	case ADVANCED_KEYFOLLOWDIR: SETVALUE(p->KeyFollowDir,bool_t,ERR_NONE); break;
	case ADVANCED_WAVEOUTPRIORITY: SETVALUECMP(p->WaveoutPriority,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_MEMORYOVERRIDE: SETVALUECOND(p->MemoryOverride,bool_t,ERR_NONE,MemGetInfo(NULL)); break;
	case ADVANCED_NOBATTERYWARNING: SETVALUE(p->NoBatteryWarning,bool_t,ERR_NONE); break;
	case ADVANCED_NOEVENTCHECKING: SETVALUECMP(p->NoEventChecking,bool_t,NodeSettingsChanged(),EqBool); break;
	case ADVANCED_CARDPLUGINS: SETVALUE(p->CardPlugins,bool_t,ERR_NONE); break;
	case ADVANCED_WIDCOMMDLL: 
		assert(Size==sizeof(bool_t));
		if (p->WidcommDLL && !*(bool_t*)Data)
			p->WidcommAudio = 1;
		break;
	}
	return Result;
}
void TestAbortQuery::quickTest()
{
	CmvautoPtr<IStmt> lQ(mSession->createStmt());
	unsigned char lVar = lQ->addVariable();
	IExprNode *lET;
	{
		Value lV[2];
		lV[0].setVarRef(0,mPropIDs[0]);
		lV[1].set(10000);
		IExprNode *lET1 = mSession->expr(OP_LT, 2, lV);

		lV[0].setVarRef(0,mPropIDs[4]);
		lV[1].set(10);
		IExprNode *lET2 = mSession->expr(OP_GT, 2, lV);

		lV[0].set(lET1);
		lV[1].set(lET2);
		IExprNode *lET3 = mSession->expr(OP_LAND, 2, lV);

		lV[0].setVarRef(0,mPropIDs[1]);
		lV[1].set("a");
		IExprNode *lET4 = mSession->expr(OP_CONTAINS, 2, lV, CASE_INSENSITIVE_OP);

		lV[0].set(lET3);
		lV[1].set(lET4);
		lET = mSession->expr(OP_LAND, 2, lV);
	}
	lQ->addCondition(lVar,lET); lET->destroy();
	uint64_t lCount = 0;
	
	ICursor *lRes;
	setAbortQ();
	for(int i = 0;i<nTimes;i++)
	{
		TVERIFYRC(lQ->execute(&lRes));
		if( (RC_TIMEOUT == lQ->count(lCount)) && (NULL == lRes) )
			cnt++;
	}
	mLogger.print("lQ->count(lCount)\n");
	mLogger.print("lQ->execute()\n");
	TVERIFY(cnt > 0);
		
	if(lRes) lRes->destroy();
	resetAbortQ();

	ICursor *lR;
	unsigned long lResultCount = 0;
	
	TVERIFYRC(lQ->count(lCount));
	TVERIFYRC(lQ->execute(&lR));
	
	if(lR)
	{
		for(IPIN *lPIN = lR->next(); lPIN != NULL; lPIN = lR->next(), lResultCount++)
			lPIN->destroy();
		lR->destroy();
	}else
		TVERIFY(false && "NULL ICursor returned");

	TVERIFY(lResultCount < lCount || lResultCount == lCount);
	
	//Values to be used by copyPINs,modifyPINs calls.
	Value lV[8];

	lV[0].setNow(); SETVATTR(lV[0], mPropIDs[7], OP_SET);
	IStream *lStream = new TestStringStream(MVTRand::getRange(10, 30) * 1024);
	SETVALUE(lV[1], mPropIDs[8], MVTApp::wrapClientStream(mSession, lStream), OP_SET);
	IStream *lStream1 = new TestStringStream(MVTRand::getRange(10, 30) * 1024);
	SETVALUE(lV[2], mPropIDs[9], MVTApp::wrapClientStream(mSession, lStream1), OP_SET);
	SETVALUE(lV[3], mPropIDs[10], MVTRand::getRange(10, 100), OP_SET);
	Tstring lStr; MVTRand::getString(lStr, 10, 100, true, false);
	SETVALUE(lV[4], mPropIDs[11], lStr.c_str(), OP_SET);
	SETVALUE(lV[5], mPropIDs[12], lStr.c_str(), OP_SET);
	Tstring lWStr; MVTRand::getString(lWStr, 10, 100, true, false);
	SETVALUE(lV[6], mPropIDs[13], lWStr.c_str(), OP_SET);
	double lDouble = (double)MVTRand::getRange(10, 1000);
	SETVALUE(lV[7], mPropIDs[14], lDouble, OP_SET);

	IStmt *lModQ = lQ->clone(STMT_UPDATE);
	lModQ->setValues(lV,8);
	IStmt *lDelQ = lQ->clone(STMT_DELETE);
	
	setAbortQ();
	for(int i = 0; i<nTimes; i++)
		if((RC_TIMEOUT == lModQ->execute()) && (RC_TIMEOUT == lDelQ->execute()))
			cnt++;
	mLogger.print("lQ->modifyPINs(lV, 8)\n");
	TVERIFY(cnt>0);

	resetAbortQ();
	TVERIFYRC(lModQ->execute());
	TVERIFYRC(lDelQ->execute());
	lModQ->destroy();
	lDelQ->destroy();
		
	setAbortQ();
	IStmt *lUDelQ = lQ->clone(STMT_UNDELETE);
	cnt = 0;
	for(int i = 0; i<nTimes; i++)
		if(RC_TIMEOUT == lUDelQ->execute())
			cnt++;	
	mLogger.print("lQ->undeletePINs()\n");
	TVERIFY(cnt>0);

	resetAbortQ();
	TVERIFYRC(lUDelQ->execute());
	lUDelQ->destroy();
	
	setAbortQ();
	IStmt *lCopyQ = lQ->clone(STMT_INSERT);
	lCopyQ->setValues(lV,8);
	for(int i = 0; i<nTimes; i++)
		if(RC_TIMEOUT == lCopyQ->execute())
			cnt++;	
	mLogger.print("lQ->copyPINs(lV,8)\n");
	TVERIFY(cnt>0);
	lCopyQ->destroy();

	mStop = true;
}
THREAD_SIGNATURE TestCustom59::threadTestCustom59(void * pC)
{
	testCustom59_s * const lC = (testCustom59_s *)pC;
	ISession * const lSession = MVTApp::startSession(lC->mTest.mStoreCtx);
	lC->mThreadId = (long int)getThreadId();
	bool lFreeRun = false;
	long lFreeStep;
	long volatile * lStepPtr = &lC->mTest.mStep;
	while (*lStepPtr < lC->mNumSteps)
	{
		RC lRC = RC_OK;
		Value lV[2];
		SETVALUE(lV[0], lC->mTest.mPropIds[0], "pomme poire banane", OP_SET);
		SETVALUE_C(lV[1], lC->mTest.mPropIds[1], (int)lC->mThreadId, OP_ADD, STORE_LAST_ELEMENT);
		lV[0].meta = lV[1].meta = META_PROP_FTINDEX;
		long const lStepIndex = *lStepPtr;
		TestCustom59::eSteps const lStep = lC->mSteps[lStepIndex];
		if (TestCustom59::kSLastSynchroStep < lStep)
		{
			lC->mTest.mOutputLock.lock();
			lC->mTest.logLineHeader(lC->mThreadIndex);
			lC->mTest.getLogger().out() << "step #" << std::dec << lStepIndex << ":";
			lC->mTest.getLogger().out() << lC->mTest.stepName(lStep);
			lC->mTest.getLogger().out() << std::endl;
			lC->mTest.mOutputLock.unlock();
		}
		switch (lStep)
		{
			case TestCustom59::kSWaiting: if (!lFreeRun) lC->mTest.nextStep(lStepIndex); break;
			case TestCustom59::kSSleepAndGo:
			{
				MVTestsPortability::threadSleep(1000);
				if (!lFreeRun)
				{
					lFreeStep = lC->mTest.detachStepping(lC->mDetachedStepping);
					lStepPtr = &lFreeStep;
					lFreeRun = true;
				}
				lFreeStep++;
				break;
			}
			case TestCustom59::kSSleep: MVTestsPortability::threadSleep(1000); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSStartTx: lSession->startTransaction(); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSCommitTx: lRC = lSession->commit(); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSRead1: if (NULL == lSession->getPIN(lC->mTest.mPID1)) lC->mDeadlocked = true; lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSRead2: if (NULL == lSession->getPIN(lC->mTest.mPID2)) lC->mDeadlocked = true; lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSRead3: if (NULL == lSession->getPIN(lC->mTest.mPID3)) lC->mDeadlocked = true; lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSWrite1: lRC = lSession->modifyPIN(lC->mTest.mPID1, lV, 2); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSWrite2: lRC = lSession->modifyPIN(lC->mTest.mPID2, lV, 2); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSWrite3: lRC = lSession->modifyPIN(lC->mTest.mPID3, lV, 2); lC->mTest.nextStep(lFreeRun, lFreeStep); break;
			case TestCustom59::kSQuickCheckFTIndexingIsolation:
			{
				IStmt * lQWord = lSession->createStmt();
				unsigned char lVar = lQWord->addVariable();
				lQWord->setConditionFT(lVar, "poire");
				ICursor * lRWord = NULL;
				lQWord->execute(&lRWord);
				if (lRWord)
				{
					IPIN * lNext;
					while (NULL != (lNext = lRWord->next()))
					{
						if (lC->mTest.mPID1 == lNext->getPID() || lC->mTest.mPID2 == lNext->getPID() || lC->mTest.mPID3 == lNext->getPID())
						{
							lC->mTest.mOutputLock.lock();
							lC->mTest.logLineHeader(lC->mThreadIndex);
							lC->mTest.getLogger().out() << "WARNING: FT found pin " << std::hex << lNext->getPID().pid << std::endl;
							lC->mTest.mOutputLock.unlock();
						}	
						lNext->destroy();
					}
					lRWord->destroy();
				}
				else
				{
					lC->mTest.logLineHeader(lC->mThreadIndex);
					lC->mTest.getLogger().out() << "WARNING: Couldn't obtain a query result!?" << std::endl;
				}
				lQWord->destroy();
				lC->mTest.nextStep(lFreeRun, lFreeStep);
				break;
			}
			default: assert(false); break;
		}

		if (RC_DEADLOCK == lRC)
			lC->mDeadlocked = true;
		else if (RC_OK != lRC)
		{
			lC->mTest.mOutputLock.lock();
			lC->mTest.logLineHeader(lC->mThreadIndex);
			lC->mTest.getLogger().out() << "Failure " << std::dec << lRC << std::endl;
			lC->mTest.mOutputLock.unlock();
		}

		if (lC->mDeadlocked)
		{
			lSession->rollback(); // Review: This will not be needed later on.

			lC->mTest.mOutputLock.lock();
			lC->mTest.logLineHeader(lC->mThreadIndex);
			lC->mTest.getLogger().out() << "DEADLOCKED" << std::endl;
			lC->mTest.mOutputLock.unlock();

			lC->mTest.detachStepping(lC->mDetachedStepping);
			lFreeStep = lC->mNumSteps;
			lStepPtr = &lFreeStep;
			lFreeRun = true;
		}
	}
	lC->mTest.detachStepping(lC->mDetachedStepping);
	lC->mTest.mOutputLock.lock();
	lC->mTest.logLineHeader(lC->mThreadIndex);
	lC->mTest.getLogger().out() << "done" << std::endl;
	lC->mTest.mOutputLock.unlock();
	lSession->terminate();
	return 0;
}