Exemplo n.º 1
0
void VariableRegistryTestFixture::testCodec(){
	fprintf(stderr, "mVariableRegistryTestFixture::testCodec()\n");			
	
	VariableRegistry *r = new VariableRegistry(GlobalBufferManager);

	Data generated_codec(r->getCodec());	
	// #codec, #componentCodec, #termination (all generated by default)
	checkCodec(generated_codec.getScarabDatum(), 2);
	CPPUNIT_ASSERT(r->getNVariables() == 3);
	
	Data test1((float)5);
	VariableProperties props(&test1, 
							  "test",
							  "Test test",
							  "Testy test test test",
							  M_NEVER, 
							  M_WHEN_CHANGED,
							  true, 
							  false,
							  M_CONTINUOUS_INFINITE,
							  "");
	
	shared_ptr<Variable> testvar =
		r->createGlobalVariable(&props);
	
	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r->getNVariables() == 4);
	
	
	//r->generateCodec();
	Data generated_codec2(r->getCodec());
	
	checkCodec(generated_codec2.getScarabDatum(), 3);
	
	shared_ptr<Variable> _testvar = r->getVariable("test");
	shared_ptr<Variable> __testvar = r->getVariable(3);
	CPPUNIT_ASSERT(_testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == testvar->getValue());

	CPPUNIT_ASSERT(r->hasVariable("test"));
	CPPUNIT_ASSERT(!r->hasVariable("test2"));
	CPPUNIT_ASSERT(r->getNVariables() == 4);
	
	// regenerate a new registry from the codec
	VariableRegistry *r2 = new VariableRegistry(GlobalBufferManager);
	r2->update(generated_codec2);
	Data generated_codec3(r2->getCodec());
	checkCodec(generated_codec3.getScarabDatum(), 3);

	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r->getNVariables() == 4);
	CPPUNIT_ASSERT(r2->getNVariables() == 4);
	
	Data test2((long)15);
	VariableProperties props2(&test2, 
							   "test2",
							   "Test2 test2",
							   "Testy test2 test2 test2",
							   M_NEVER, 
							   M_WHEN_CHANGED,
							   true, 
							   false,
							   M_CONTINUOUS_INFINITE,
							   "");
	shared_ptr<Variable> testvar2 =
		r2->createGlobalVariable(&props2);
	
	_testvar = r2->getVariable("test");
	__testvar = r2->getVariable(3);
	CPPUNIT_ASSERT(_testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == _testvar->getValue());
	shared_ptr<Variable> _testvar2 = r2->getVariable("test2");
	shared_ptr<Variable> __testvar2 = r2->getVariable(4);
	CPPUNIT_ASSERT(_testvar2->getValue() == testvar2->getValue());
	CPPUNIT_ASSERT(__testvar2->getValue() == testvar2->getValue());
	CPPUNIT_ASSERT(__testvar2->getValue() == _testvar2->getValue());

	CPPUNIT_ASSERT(r2->hasVariable("test"));
	CPPUNIT_ASSERT(r2->hasVariable("test2"));
	CPPUNIT_ASSERT(r2->getNVariables() == 5);

	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test2").getInteger() == 15);
	
	Data generated_codec4(r2->getCodec());
	checkCodec(generated_codec4.getScarabDatum(), 4);
	
	delete r;
	delete r2;
}
Exemplo n.º 2
0
void VariableRegistryTestFixture::testCodec(){
	VariableRegistry *r = new VariableRegistry(global_outgoing_event_buffer);

    Datum generated_codec(r->generateCodecDatum());	
	// #codec, #componentCodec, #termination (all generated by default)
	checkCodec(generated_codec, 0);
	CPPUNIT_ASSERT(r->getNVariables() == 0);
	
    Datum test1((float)5);
	VariableProperties props(&test1, 
							  "test",
							  "Test test",
							  "Testy test test test",
							  M_NEVER, 
							  M_WHEN_CHANGED,
							  true, 
							  false,
							  M_CONTINUOUS_INFINITE,
							  "");
	
	shared_ptr<Variable> testvar =
                r->createGlobalVariable(&props);
	int n_variables = 1;
    
	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r->getNVariables() == n_variables);
	
	
	//r->generateCodec();
    Datum generated_codec2(r->generateCodecDatum());
	
	checkCodec(generated_codec2, n_variables);
	
	shared_ptr<Variable> _testvar = r->getVariable("test");
	shared_ptr<Variable> __testvar = r->getVariable(N_RESERVED_CODEC_CODES);
    CPPUNIT_ASSERT(__testvar != NULL);
	CPPUNIT_ASSERT(_testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == testvar->getValue());

	CPPUNIT_ASSERT(r->hasVariable("test"));
	CPPUNIT_ASSERT(!r->hasVariable("test2"));
	CPPUNIT_ASSERT(r->getNVariables() == 1);
	
	// regenerate a new registry from the codec
	VariableRegistry *r2 = new VariableRegistry(global_outgoing_event_buffer);
	r2->updateFromCodecDatum(generated_codec2);
    Datum generated_codec3(r2->generateCodecDatum());
	checkCodec(generated_codec3, 1);

	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r->getNVariables() == n_variables);
	CPPUNIT_ASSERT(r2->getNVariables() == n_variables);
	
    Datum test2((long)15);
	VariableProperties props2(&test2, 
							   "test2",
							   "Test2 test2",
							   "Testy test2 test2 test2",
							   M_NEVER, 
							   M_WHEN_CHANGED,
							   true, 
							   false,
							   M_CONTINUOUS_INFINITE,
							   "");
	shared_ptr<Variable> testvar2 =
            r2->createGlobalVariable(&props2);
    
    n_variables++;
	
	_testvar = r2->getVariable("test");
	__testvar = r2->getVariable(N_RESERVED_CODEC_CODES);
	CPPUNIT_ASSERT(_testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == testvar->getValue());
	CPPUNIT_ASSERT(__testvar->getValue() == _testvar->getValue());
	shared_ptr<Variable> _testvar2 = r2->getVariable("test2");
	shared_ptr<Variable> __testvar2 = r2->getVariable(N_RESERVED_CODEC_CODES + 1);
	CPPUNIT_ASSERT(_testvar2->getValue() == testvar2->getValue());
	CPPUNIT_ASSERT(__testvar2->getValue() == testvar2->getValue());
	CPPUNIT_ASSERT(__testvar2->getValue() == _testvar2->getValue());

	CPPUNIT_ASSERT(r2->hasVariable("test"));
	CPPUNIT_ASSERT(r2->hasVariable("test2"));
	CPPUNIT_ASSERT(r2->getNVariables() == n_variables);

	CPPUNIT_ASSERT(r->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test").getInteger() == 5);
	CPPUNIT_ASSERT(r2->lookupVariable("test2").getInteger() == 15);
	
    Datum generated_codec4(r2->generateCodecDatum());
	checkCodec(generated_codec4, 2);
	
	delete r;
	delete r2;
}