static void run_tests_inner3L()
{
	TNoDefaults nd;
	auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("jaikutest")));
	auto_ptr<CBaActiveScheduler> sched(new (ELeave) CBaActiveScheduler);
	CActiveScheduler::Install(sched.get());

	c->SetDataDir(_L("c:\\system\\data\\context\\"), false);
	c->SetSettings(CBlackBoardSettings::NewL(*c, nd, KCLSettingsTuple));
	auto_ptr<CBBDataFactory> f(CBBDataFactory::NewL());
	c->SetBBDataFactory(f.get());
	auto_ptr<CBBSession> sess(CBBSession::NewL(*c, f.get()));
	c->SetBBSession(sess.get());
	c->SetActiveErrorReporter(output);
	
	c->BBSession()->DeleteL(KComponentVersionTuple, KNullDesC, ETrue);
	c->BBSession()->DeleteL(KComponentFunctionalityTuple, KNullDesC, ETrue);
	c->BBSession()->DeleteL(KComponentNameTuple, KNullDesC, ETrue);
	c->BBSession()->DeleteL(KComponentStateTuple, KNullDesC, ETrue);
	c->BBSession()->DeleteL(KComponentErrorCountTuple, KNullDesC, ETrue);
	c->BBSession()->DeleteL(KComponentErrorInfoTuple, KNullDesC, ETrue);
	
	auto_ptr<CBBRecovery> rec(CBBRecovery::NewL());
	MRecovery::TState state=rec->GetState( TUid::Uid(1), 4 );
	TEST_EQUALS( (TInt)state, (TInt)MRecovery::EUnknown, _L("recovery3:0:1"));
	rec->SetState(TUid::Uid(1), 4, MRecovery::ERunning );
	state=rec->GetState( TUid::Uid(1), 4 );
	TEST_EQUALS( (TInt)state, (TInt)MRecovery::ERunning, _L("recovery3:0:2"));
	
	rec->SetState(TUid::Uid(1), 4, MRecovery::EFailed);
	state=rec->GetState( TUid::Uid(1), 4 );
	TEST_EQUALS( (TInt)state, (TInt)MRecovery::EFailed, _L("recovery3:0:3"));
	TInt errors=rec->GetErrorCount( TUid::Uid(1), 4 );
	TEST_EQUALS( errors, 1, _L("recovery3:0:4"));
}
Example #2
0
static void stun_resp_handler(int err, uint16_t scode, const char *reason,
			      const struct stun_msg *msg, void *arg)
{
	struct test *test = arg;
	struct stun_attr *attr;
	(void)reason;

	if (err)
		goto out;

	++test->n_resp;

	/* verify STUN response */
	TEST_EQUALS(0, scode);
	TEST_EQUALS(0x0101, stun_msg_type(msg));
	TEST_EQUALS(STUN_CLASS_SUCCESS_RESP, stun_msg_class(msg));
	TEST_EQUALS(STUN_METHOD_BINDING, stun_msg_method(msg));
	TEST_EQUALS(0, stun_msg_chk_fingerprint(msg));

	attr = stun_msg_attr(msg, STUN_ATTR_XOR_MAPPED_ADDR);
	TEST_ASSERT(attr != NULL);

	test->mapped_addr = attr->v.sa;

 out:
	if (err)
		test->err = err;

	/* done */
	re_cancel();
}
Example #3
0
static int test_natbd_genalg(struct fixture *fix)
{
	struct nat_genalg *ng;
	int err;

	err = nat_genalg_alloc(&ng, &fix->srv->laddr, IPPROTO_UDP, NULL,
			       nat_genalg_handler, fix);
	if (err)
		return err;

	err = nat_genalg_start(ng);
	if (err)
		goto out;

	err = re_main_timeout(200);
	if (err)
		goto out;

	if (fix->err) {
		err = fix->err;
		goto out;
	}

	/* we have no NAT so there should be no Generic ALG */
	TEST_EQUALS(0, fix->scode);
	TEST_EQUALS(-1, fix->genalg_status);

 out:

	mem_deref(ng);
	return err;
}
Example #4
0
TEST_DEFINE_TEST(TestCtx, ObjectTests)
{
    auto t = Module.GetRootObject<test::IObjectTests>("GetTests");
    if (!t)
    {
        TEST_REPORT_ERROR("ObjectTests not implemented!");
        return;
    }

    auto some_obj = t->ReturnNewObject();
    TEST_THROWS_NOTHING(some_obj->Method());

    TEST_EQUALS((bool)t->ReturnNull(), false);
    TEST_EQUALS(t->CheckNotNull(nullptr), false);
    TEST_EQUALS(t->CheckNotNull(some_obj), true);

    TEST_EQUALS((bool)t->CallbackReturn(Ctx.MakeComponent<test::IObjectTestsCallbackReturn, ObjectTestsCallback>(some_obj)), true);
    auto cb = Ctx.MakeComponent<test::IObjectTestsCallbackReturn, ObjectTestsCallback>(nullptr);
    TEST_EQUALS((bool)t->CallbackReturn(cb), false);
    TEST_EQUALS(t->CallbackParam(joint::Cast<test::IObjectTestsCallbackParam>(cb), nullptr), false);
    TEST_EQUALS(t->CallbackParam(joint::Cast<test::IObjectTestsCallbackParam>(cb), some_obj), true);

    auto o_impl = Ctx.MakeComponentWrapper<SomeObject>();
    auto o = Ctx.MakeComponentProxy<test::ISomeObject>(o_impl);

    TEST_THROWS_NOTHING(t->InvokeObjectMethod(o));
    TEST_EQUALS(o_impl->GetInvokationsCount(), 1);

    auto o2 = t->ReturnSameObject(o);
    o2->Method();
    TEST_EQUALS(o_impl->GetInvokationsCount(), 2);
}
Example #5
0
/*---------------------------------------------------------------------------*/
void
test_sensor_deactivate(struct sensors_sensor sensor)
{
//  TEST_BEGIN(name);

  TEST_CODE();
  TEST_EQUALS(SENSORS_DEACTIVATE(sensor), 1);

  TEST_POST();
  //TEST_EQUALS(sensor.status(SENSORS_ACTIVE), 0);  @TODO: check
  TEST_EQUALS(sensor.status(SENSORS_READY), 1);

//  TEST_END();
}
Example #6
0
/*---------------------------------------------------------------------------*/
void
test_acc_value()
{
  TEST_PRE();
  TEST_EQUALS(acc_sensor.status(SENSORS_ACTIVE), 1);
  
  TEST_CODE();
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_SENSITIVITY, ACC_2G), 1);
  assert_acc_value();
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_SENSITIVITY, ACC_4G), 1);
  assert_acc_value();
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_SENSITIVITY, ACC_8G), 1);
  assert_acc_value();
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_SENSITIVITY, ACC_16G), 1);
  assert_acc_value();
}
Example #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(etimer_test_process, ev, data)
{
  PROCESS_BEGIN();

  TEST_BEGIN("etimer-test");

  static int idx;

  for(idx = 0; idx < TEST_CONF_ETIMERS; idx++) {
    etimer_set(&et[idx], times[idx]);
  }

  idx = 0;
  while(running) {

    PROCESS_YIELD_UNTIL(ev == PROCESS_EVENT_TIMER);

    printf("event arrived from\n", data);
    // check if events arrive in the same order we placed them
    TEST_EQUALS((struct etimer*) data - &et[0], evt_orders[idx++]);

    if (idx == TEST_CONF_ETIMERS) {
      TESTS_DONE();
    }

  }

  TEST_END();


  PROCESS_END();
}
Example #8
0
int test_rtcp_encode(void)
{
	struct mbuf *mb;
	const size_t sz = sizeof(rtcp_msg) - 1;
	const uint32_t srcv[2] = {0x12345678, 0x00abcdef};
	int err = 0;

	mb = mbuf_alloc(512);
	if (!mb)
		return ENOMEM;


	err |= rtcp_encode(mb, RTCP_SR, 1, 0x12345678, 0x00112233,
			   0x44556677, 0x22332233, 0x00001111, 0x00002222,
			   encode_handler, 0);
	err |= rtcp_encode(mb, RTCP_RR, 1, 0x12345678, encode_handler, 0);
	err |= rtcp_encode(mb, RTCP_SDES, 1, sdes_encode_handler, 0);
	err |= rtcp_encode(mb, RTCP_BYE, 2, srcv, "ciao");
	err |= rtcp_encode(mb, RTCP_APP, 0, 0x12345678, "name", "data",
			   (size_t)4);
	err |= rtcp_encode(mb, RTCP_FIR, 0, 0x12345678);
	err |= rtcp_encode(mb, RTCP_NACK, 0, 0x12345678, 0x89ab, 0xcdef);
	err |= rtcp_encode(mb, RTCP_RTPFB, RTCP_RTPFB_GNACK,
			   0x12345678, 0xfedcba98, gnack_encode, 0);
	err |= rtcp_encode(mb, RTCP_PSFB, RTCP_PSFB_PLI,
			   0x12345678, 0xfedcba98, NULL, 0);
	err |= rtcp_encode(mb, RTCP_PSFB, RTCP_PSFB_SLI,
			   0x12345678, 0xfedcba98, sli_encode, 0);
	if (err)
		goto out;

	if (mb->end != sz) {
		err = EPROTO;
	}
	if (0 != memcmp(mb->buf, rtcp_msg, mb->end)) {
		err = EBADMSG;
	}

	if (err) {
		DEBUG_WARNING("encode error: %m\n", err);
		hexdump(stderr, mb->buf, mb->end);
	}

	mb->pos = 0;
	while (mbuf_get_left(mb) >= 4 && !err) {
		struct rtcp_msg *msg = NULL;
		err = rtcp_decode(&msg, mb);
		msg = mem_deref(msg);
	}
	if (err)
		goto out;

	/* verify that rtcp_decode() read the whole buffer */
	TEST_EQUALS(mb->end, mb->pos);

 out:
	mem_deref(mb);
	return err;
}
static void run_tests_innerL()
{
	TNoDefaults nd;
	auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("jaikutest")));
	auto_ptr<CBaActiveScheduler> sched(new (ELeave) CBaActiveScheduler);
	CActiveScheduler::Install(sched.get());

	c->SetDataDir(_L("c:\\system\\data\\context\\"), false);
	c->SetSettings(CBlackBoardSettings::NewL(*c, nd, KCLSettingsTuple));
	auto_ptr<CBBDataFactory> f(CBBDataFactory::NewL());
	c->SetBBDataFactory(f.get());
	auto_ptr<CBBSession> sess(CBBSession::NewL(*c, f.get()));
	c->SetBBSession(sess.get());
	c->SetActiveErrorReporter(output);
	
	{
		auto_ptr<CComponent1> c1( new (ELeave) CComponent1 );
		c1->ConstructL();
		CActiveScheduler::Start();
		TEST_EQUALS( 1, c1->iErrorCount, _L("comp1:1") );
	}
	{
		TLogRecovery r;
		c->SetRecovery(&r);
		auto_ptr<CComponent1> c1( new (ELeave) CComponent1 );
		c1->ConstructL();
		CActiveScheduler::Start();
		TEST_EQUALS( 1, c1->iErrorCount, _L("comp2:1") );
		TEST_EQUALS( (TInt)MRecovery::ERestarting, (TInt)r.iState, _L("recovery:1") );
		CActiveScheduler::Start();
		TEST_EQUALS( 2, c1->iErrorCount, _L("comp2:2") );
		TEST_EQUALS( (TInt)MRecovery::ERestarting, (TInt)r.iState, _L("recovery:2") );
		
		CActiveScheduler::Start();
		TEST_EQUALS( 3, c1->iErrorCount, _L("comp2:3") );
		TEST_EQUALS( (TInt)MRecovery::ERestarting, (TInt)r.iState, _L("recovery:3") );

		CActiveScheduler::Start();
		TEST_EQUALS( 4, c1->iErrorCount, _L("comp2:4") );
		TEST_EQUALS( (TInt)MRecovery::EFailed, (TInt)r.iState, _L("recovery:4") );
		TInt stack_found=r.iErrorInfo->StackTrace().FindF(_L("StartL"));
		TEST_NOT_EQUALS(KErrNotFound, stack_found, _L("stack:1"));
		
		c->SetRecovery(0);
	}
	
	CActiveScheduler::Install(0);
}
Example #10
0
int test_sdp_extmap(void)
{
	static const char *extmapv[3] = {
		"extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level",
		"extmap:2/sendrecv http://example.com/ext.htm#xmeta short",
		"extmap:4096/recvonly URI-gps-string"
	};
	struct sdp_extmap ext;
	int err = 0;

	/* extmap 1 */
	err = sdp_extmap_decode(&ext, extmapv[0]);
	TEST_EQUALS(0, err);
	TEST_STRCMP("urn:ietf:params:rtp-hdrext:ssrc-audio-level",
		    strlen("urn:ietf:params:rtp-hdrext:ssrc-audio-level"),
		    ext.name.p, ext.name.l);
	TEST_ASSERT(!pl_isset(&ext.attrs));
	TEST_EQUALS(SDP_SENDRECV, ext.dir);
	TEST_ASSERT(!ext.dir_set);
	TEST_EQUALS(1, ext.id);

	/* extmap 2 */
	err = sdp_extmap_decode(&ext, extmapv[1]);
	TEST_EQUALS(0, err);
	TEST_STRCMP("http://example.com/ext.htm#xmeta",
		    strlen("http://example.com/ext.htm#xmeta"),
		    ext.name.p, ext.name.l);
	TEST_STRCMP("short", strlen("short"),
		    ext.attrs.p, ext.attrs.l);
	TEST_EQUALS(SDP_SENDRECV, ext.dir);
	TEST_ASSERT(ext.dir_set);
	TEST_EQUALS(2, ext.id);

	/* extmap 3 */
	err = sdp_extmap_decode(&ext, extmapv[2]);
	TEST_EQUALS(0, err);
	TEST_STRCMP("URI-gps-string",
		    strlen("URI-gps-string"),
		    ext.name.p, ext.name.l);
	TEST_ASSERT(!pl_isset(&ext.attrs));
	TEST_EQUALS(SDP_RECVONLY, ext.dir);
	TEST_ASSERT(ext.dir_set);
	TEST_EQUALS(4096, ext.id);

 out:
	return err;
}
Example #11
0
static void sip_resp_handler(int err, const struct sip_msg *msg, void *arg)
{
    struct test *test = arg;

    if (err) {
        test->err = err;
        re_cancel();
        return;
    }

    ++test->n_resp;

    /* verify the SIP response message */
    TEST_ASSERT(msg != NULL);
    TEST_EQUALS(200, msg->scode);
    TEST_STRCMP("REGISTER", 8, msg->cseq.met.p, msg->cseq.met.l);
    TEST_EQUALS(test->tp, msg->tp);

out:
    if (err)
        test->err = err;
    re_cancel();
}
static void run_tests_inner4L()
{
	RAChunk stackchunk;
	stackchunk.CreateGlobalLA(_L("jaikutest2"), 4096, 4096);
	{
		*(TInt*)stackchunk.Base()=0;
		char* iCallStackZero=(char*)stackchunk.Base() + 4;
		TInt iCallStackSize=stackchunk.Size();
		TUint* uidp=(TUint*)(iCallStackZero+iCallStackSize-16);
		TInt* idp=(TInt*)(iCallStackZero+iCallStackSize-12);
		*uidp=0;
		*idp=0;
	}
	auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("jaikutest")));
	auto_ptr<CBaActiveScheduler> sched(new (ELeave) CBaActiveScheduler);
	CActiveScheduler::Install(sched.get());

	TNoDefaults nd;
	c->SetDataDir(_L("c:\\system\\data\\context\\"), false);
	c->SetSettings(CBlackBoardSettings::NewL(*c, nd, KCLSettingsTuple));
	auto_ptr<CBBDataFactory> f(CBBDataFactory::NewL());
	c->SetBBDataFactory(f.get());
	auto_ptr<CBBSession> sess(CBBSession::NewL(*c, f.get()));
	c->SetBBSession(sess.get());
	auto_ptr<CBBRecovery> rec(CBBRecovery::NewL());
	c->SetRecovery(rec.get());
	
	MRecovery::TState state=MRecovery::EUnknown;
	while (state!=MRecovery::EDisabled) {
		RAThread thread;
		thread.CreateLA(_L("jaikutest3"),
				&run_thread_4,
				20*1024,
				128*1024,
				32*1048*1024,
				0);
		thread.SetPriority(EPriorityNormal);
		TRequestStatus s;
		thread.Logon(s);
		thread.Resume();
		User::WaitForRequest(s);
	
		state=rec->GetState( TUid::Uid(5), 1 );
	}
	TEST_EQUALS( (TInt)state, (TInt)MRecovery::EDisabled, _L("recovery4:0:1"));
}
Example #13
0
/*---------------------------------------------------------------------------*/
void
test_acc_conf_odr()
{
  TEST_PRE();
  TEST_EQUALS(acc_sensor.status(SENSORS_ACTIVE), 1);
  
  TEST_CODE();
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_DATA_RATE, ACC_0HZ10), 1);
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_DATA_RATE, ACC_6HZ25), 1);
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_DATA_RATE, ACC_25HZ), 1);
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_DATA_RATE, ACC_100HZ), 1);
  TEST_EQUALS(acc_sensor.configure(ACC_CONF_DATA_RATE, ACC_400HZ), 1);
}
void test_bbclient_inner(MApp_context* c)
{
	CALLSTACKITEM_N(_CL("RDebug"), _CL("Print"));

	TFileName t=c->DataDir();
	t.Append(_L("TUPLE.db"));
	c->Fs().Delete(t);

	RABBClient bbc; bbc.ConnectLA();

	TTupleName tn1={ { 0x1 }, 0x1 };
	TComponentName cn1={ { 0x1 }, 0x1 };

	TRequestStatus s=KRequestPending;
	TBuf8<10> b=_L8("xxx");
	TUint id=0;
	bbc.Put(tn1, _L(""), cn1, b, EBBPriorityNormal, ETrue, id, s);
	User::WaitForRequest(s);

	TBuf8<10> b2;
	s=KRequestPending;
	TFullArgs a;
	bbc.Get(tn1, _L(""), a, b2, s);
	User::WaitForRequest(s);
	TEST_EQUALS(b, b2, _L("bbc::0"));

	TBBPriority prio[2]={ EBBPriorityNormal, EBBPriorityHigh };
	TInt i;
	for (i=0; i<2; i++) {
		TTupleName tn2={ { 0x2 }, 0x1 };
		s=KRequestPending;
		bbc.AddNotificationL(tn2, EFalse, prio[i], s);
		User::WaitForRequest(s);
		if (i==0) 
			TEST_EQUALS(s.Int(), KErrNone, _L("bbc::1"));
		else
			TEST_EQUALS(s.Int(), KErrAlreadyExists, _L("bbc::1"));

		b=_L8("abc");
		s=KRequestPending;
		bbc.Put(tn2, _L(""), cn1, b, prio[i], ETrue, id, s);
		User::WaitForRequest(s);
		TEST_EQUALS(s.Int(), KErrNone, _L("bbc::2"));
		s=KRequestPending;
		bbc.WaitForNotify(a, b2, s);
		User::WaitForRequest(s);
		TEST_EQUALS(s.Int(), KErrNone, _L("bbc::3"));
		TEST_EQUALS(b, b2, _L("bbc::4"));
	}
}
static void run_tests_inner2L()
{
	RAChunk stackchunk;
	stackchunk.CreateGlobalLA(_L("jaikutest"), 4096, 4096);
	{
		*(TInt*)stackchunk.Base()=0;
		char* iCallStackZero=(char*)stackchunk.Base() + 4;
		TInt iCallStackSize=stackchunk.Size();
		TUint* uidp=(TUint*)(iCallStackZero+iCallStackSize-16);
		TInt* idp=(TInt*)(iCallStackZero+iCallStackSize-12);
		*uidp=0;
		*idp=0;
	}

	{
		auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("jaikutest")));
		TUid gotuid; TInt gotid;
		c->GetCurrentComponent(gotuid, gotid);
		TEST_EQUALS ( (TInt)gotuid.iUid, 0, _L("recovery2:0:1") );
		TEST_EQUALS ( (TInt)gotid, 0, _L("recovery2:0:2") );
		c->SetCurrentComponent(TUid::Uid(1), 3);
		c->GetCurrentComponent(gotuid, gotid);
		TEST_EQUALS ( (TInt)gotuid.iUid, 1, _L("recovery2:1:1") );
		TEST_EQUALS ( (TInt)gotid, 3, _L("recovery2:1:2") );
	}
	{
		auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("jaikutest")));
		TUid gotuid; TInt gotid;
		c->GetCurrentComponent(gotuid, gotid);
		TEST_EQUALS ( (TInt)gotuid.iUid, 0, _L("recovery2:2:1") );
		TEST_EQUALS ( (TInt)gotid, 0, _L("recovery2:2:2") );
		c->GetInitialComponent(gotuid, gotid);
		TEST_EQUALS ( (TInt)gotuid.iUid, 1, _L("recovery2:3:1") );
		TEST_EQUALS ( (TInt)gotid, 3, _L("recovery2:3:2") );
	}
}
void test_oom2(MRunnable2& r, TInt aMinFail=0, TInt start_with=1)
{
#ifdef __WINS__
	// grow heap so that memory leak addresses
	// are available early
	void* p=User::Alloc(16*1024*1024);
	User::Free(p);
#endif

	TInt err=0;
	TInt fail_on=start_with;
	err=KErrNoMemory;

	//fail_on=108;
	while (err==KErrNoMemory || (fail_on<aMinFail && err==KErrNone) ) {
		TBuf<20> m;
		m.AppendNum(fail_on); m.Append(_L("\n"));
		//output->Write(m);
		RDebug::Print(m);
		if (fail_on==109) {
			TInt x;
			x=0;
		}
		User::__DbgMarkStart(RHeap::EUser);
		{
			User::__DbgSetAllocFail(RHeap::EUser, RHeap::EDeterministic, fail_on);
			CC_TRAP(err, r.run());
			User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1);
			r.stop();
		}
		User::__DbgMarkEnd(RHeap::EUser,0);
		++fail_on;
	}
	User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1);
	test_state.Append(_L(":oom_")); test_state.AppendNum(fail_on);
	TEST_EQUALS(err, KErrNone, test_state);
}
void test_oom(MRunnable& r)
{
	void* p=User::Alloc(16*1024*1024);
	User::Free(p);

	TInt err=0;
	TInt fail_on=1;
	err=KErrNoMemory;
	while (err==KErrNoMemory) {
		if (fail_on==13) {
			TInt x;
			x=0;
		}
		User::__DbgSetAllocFail(RHeap::EUser, RHeap::EDeterministic, fail_on);
		User::__DbgMarkStart(RHeap::EUser);
		CC_TRAPIGNORE(err, KErrNoMemory, r.run());
		User::__DbgMarkEnd(RHeap::EUser,0);
		User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1);
		++fail_on;
	}
	User::__DbgSetAllocFail(RHeap::EUser, RHeap::ENone, 1);
	test_state.Append(_L(":oom_")); test_state.AppendNum(fail_on);
	TEST_EQUALS(err, KErrNone, test_state);
}
static void run_tests_innerL()
{
	TNoDefaults nd;
	auto_ptr<CApp_context> c(CApp_context::NewL(true, _L("locatest")));
	auto_ptr<CBaActiveScheduler> sched(new (ELeave) CBaActiveScheduler);
	CActiveScheduler::Install(sched.get());

	c->SetDataDir(_L("c:\\system\\data\\context\\"), false);
	c->SetSettings(CBlackBoardSettings::NewL(*c, nd, KCLSettingsTuple));
	auto_ptr<CBBDataFactory> f(CBBDataFactory::NewL());
	c->SetBBDataFactory(f.get());
	auto_ptr<CBBSession> sess(CBBSession::NewL(*c, f.get()));
	c->SetBBSession(sess.get());
	c->SetActiveErrorReporter(output);

	auto_ptr<CPresenceMaintainer> pmp(CPresenceMaintainer::NewL(*c,
		0, 0, 0, 0));
	CPresenceMaintainerImpl* pm=(CPresenceMaintainerImpl*)pmp.get();
	_LIT(cn, "cellname");
	TBBLongString cellname(_L("cell1"), cn);
	CBBSensorEvent e(cn, KCellNameTuple, f.get());
	e.iData.SetOwnsValue(EFalse);
	e.iData.SetValue(&cellname);
	e.iStamp=TTime(100);
	pm->NewSensorEventL(KCellNameTuple, KNullDesC, e);

	TInt isactive=0;
	if (pm->iNonsignificantTimer->IsActive()) isactive=1;
	TEST_EQUALS( 1, isactive, _L("nonsig1") );

	{
		TBBBaseInfo b;
		b.iCurrent.iEntered=TTime(100);
		b.iCurrent.iLeft=TTime(0);
		b.iCurrent.iBaseName=_L("cell2");
		e.iData.SetValue(&b);
		pm->NewSensorEventL(KBaseTuple, KNullDesC, e);
		if (pm->iNonsignificantTimer->IsActive()) isactive=1;
		else isactive=0;
		TEST_EQUALS( 0, isactive, _L("nonsig2") );
	}

	cellname()=_L("cell3");
	e.iStamp=TTime(100);
	e.iData.SetValue(&cellname);
	pm->NewSensorEventL(KCellNameTuple, KNullDesC, e);
	if (pm->iNonsignificantTimer->IsActive()) isactive=1;
	else isactive=0;
	TEST_EQUALS( 0, isactive, _L("nonsig3") );

	cellname()=_L("cell4");
	e.iStamp=TTime(110);
	e.iData.SetValue(&cellname);
	pm->NewSensorEventL(KCellNameTuple, KNullDesC, e);
	if (pm->iNonsignificantTimer->IsActive()) isactive=1;
	else isactive=0;
	TEST_EQUALS( 0, isactive, _L("nonsig4") );

	{
		TBBBaseInfo b;
		b.iCurrent.iEntered=TTime(100);
		b.iCurrent.iLeft=TTime(110);
		b.iCurrent.iBaseName=_L("cell2");
		e.iData.SetValue(&b);
		pm->NewSensorEventL(KBaseTuple, KNullDesC, e);
		if (pm->iNonsignificantTimer->IsActive()) isactive=1;
		else isactive=0;
		TEST_EQUALS( 0, isactive, _L("nonsig5") );
	}

	cellname()=_L("cell3");
	e.iStamp=TTime(120);
	e.iData.SetValue(&cellname);
	pm->NewSensorEventL(KCellNameTuple, KNullDesC, e);
	if (pm->iNonsignificantTimer->IsActive()) isactive=1;
	else isactive=1;
	TEST_EQUALS( 1, isactive, _L("nonsig6") );

}
	static void run_tests_innerL() {
		CALLSTACKITEMSTATIC_N(_CL("CStackTest"), _CL("CallLeaving"));
		TRAPD(err, run_destroyL());
		TEST_EQUALS( err, -2, _L("stacktest"));
	}
Example #20
0
static int test_stun_request(int proto, bool natted)
{
	struct stunserver *srv = NULL;
	struct stun_ctrans *ct = NULL;
	struct nat *nat = NULL;
	struct test test;
	struct sa laddr, public_addr;
	int err;

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

	err = stunserver_alloc(&srv);
	if (err)
		goto out;

	err = stun_alloc(&test.stun, NULL, NULL, NULL);
	if (err)
		goto out;

	if (proto == IPPROTO_UDP) {
		err = sa_set_str(&laddr, "127.0.0.1", 0);
		TEST_ERR(err);

		err = udp_listen(&test.us, &laddr, udp_recv_handler, &test);
		if (err)
			goto out;
		err = udp_local_get(test.us, &laddr);
		TEST_ERR(err);
	}

	if (natted) {
		err = sa_set_str(&public_addr, "4.5.6.7", 0);
		TEST_ERR(err);

		err = nat_alloc(&nat, srv->us, &public_addr);
		if (err)
			goto out;

		sa_set_port(&public_addr, sa_port(&laddr));
	}
	else {
		public_addr = laddr;
	}

	err = stun_request(&ct, test.stun, proto, test.us,
			   stunserver_addr(srv, proto), 0,
			   STUN_METHOD_BINDING, NULL, 0, true,
			   stun_resp_handler, &test, 0);
	if (err)
		goto out;

	TEST_ASSERT(ct != NULL);

	err = re_main_timeout(100);
	if (err)
		goto out;

	if (srv->err) {
		err = srv->err;
		goto out;
	}
	if (test.err) {
		err = test.err;
		goto out;
	}

	/* verify results */
	TEST_ASSERT(srv->nrecv >= 1);
	TEST_EQUALS(1, test.n_resp);

	if (proto == IPPROTO_UDP) {
		TEST_SACMP(&public_addr, &test.mapped_addr, SA_ALL);
	}

 out:
	mem_deref(test.stun);
	mem_deref(test.us);
	mem_deref(nat);
	mem_deref(srv);

	return err;
}
Example #21
0
static int test_stun_req_attributes(void)
{
	struct stun_msg *msg = NULL;
	struct mbuf *mb;
	struct stun_attr *attr;
	const uint64_t rsv_token = 0x1100c0ffee;
	const uint32_t lifetime = 3600;
	const uint16_t chan = 0x4000;
	const uint8_t req_addr_fam = AF_INET;
	int err;

	mb = mbuf_alloc(1024);
	if (!mb) {
		err = ENOMEM;
		goto out;
	}

	err = stun_msg_encode(mb, STUN_METHOD_BINDING, STUN_CLASS_REQUEST,
			      tid, NULL, NULL, 0, false,
			      0x00, 4,
			      STUN_ATTR_REQ_ADDR_FAMILY, &req_addr_fam,
			      STUN_ATTR_CHANNEL_NUMBER, &chan,
			      STUN_ATTR_LIFETIME, &lifetime,
			      STUN_ATTR_RSV_TOKEN, &rsv_token);
	if (err)
		goto out;

	/* Decode STUN message */
	mb->pos = 0;
	err = stun_msg_decode(&msg, mb, NULL);
	if (err)
		goto out;

	TEST_EQUALS(STUN_CLASS_REQUEST, stun_msg_class(msg));
	TEST_EQUALS(STUN_METHOD_BINDING, stun_msg_method(msg));

	/* verify integer attributes of different sizes */

	/* 8-bit */
	attr = stun_msg_attr(msg, STUN_ATTR_REQ_ADDR_FAMILY);
	TEST_ASSERT(attr != NULL);
	TEST_EQUALS(req_addr_fam, attr->v.req_addr_family);

	/* 16-bit */
	attr = stun_msg_attr(msg, STUN_ATTR_CHANNEL_NUMBER);
	TEST_ASSERT(attr != NULL);
	TEST_EQUALS(chan, attr->v.channel_number);

	/* 32-bit */
	attr = stun_msg_attr(msg, STUN_ATTR_LIFETIME);
	TEST_ASSERT(attr != NULL);
	TEST_EQUALS(lifetime, attr->v.lifetime);

	/* 64-bit */
	attr = stun_msg_attr(msg, STUN_ATTR_RSV_TOKEN);
	TEST_ASSERT(attr != NULL);
	TEST_EQUALS(rsv_token, attr->v.rsv_token);

 out:
	mem_deref(msg);
	mem_deref(mb);
	return err;
}
void test_for_error_leave(TInt aOccurred, TInt aExpected, const TDesC& name)
{
	if (aOccurred!=aExpected) User::LeaveIfError(aOccurred);
	TEST_EQUALS(aOccurred, aExpected, name);
}
Example #23
0
int test_rtcp_encode_afb(void)
{
	uint32_t ssrc_packet_sender, ssrc_media_source;
	const char *afb_payload = "AFB tull";
	struct rtcp_msg *msg = NULL;
	struct mbuf *mb;
	int err = 0;

	mb = mbuf_alloc(512);
	if (!mb)
		return ENOMEM;

	ssrc_packet_sender = 0xbad00bad;
	ssrc_media_source = 0; /* always 0 */
	err = rtcp_encode(mb, RTCP_PSFB, RTCP_PSFB_AFB,
			  ssrc_packet_sender, ssrc_media_source,
			  afb_encode_handler, afb_payload);
	if (err)
		goto out;

	mb->pos = 0;
	err = rtcp_decode(&msg, mb);
	if (err)
		goto out;

	if (msg->hdr.count != RTCP_PSFB_AFB) {
		DEBUG_WARNING("expected AFB, got fmt=%u\n", msg->hdr.count);
		err = EPROTO;
		goto out;
	}

	if (msg->r.fb.ssrc_packet != ssrc_packet_sender ||
	    msg->r.fb.ssrc_media  != ssrc_media_source) {
		DEBUG_WARNING("error in SSRC encoding\n");
		err = EBADMSG;
		goto out;
	}

	if (!msg->r.fb.fci.afb ||
	    mbuf_get_left(msg->r.fb.fci.afb) != strlen(afb_payload)) {
		DEBUG_WARNING("error in AFB mbuf (left=%u, size=%u)\n",
			      mbuf_get_left(msg->r.fb.fci.afb),
			      strlen(afb_payload));
		err = EBADMSG;
		goto out;
	}

	if (0 != memcmp(mbuf_buf(msg->r.fb.fci.afb),
			afb_payload,
			strlen(afb_payload))) {
		DEBUG_WARNING("error in AFB mbuf content\n");
		err = EBADMSG;
		goto out;
	}

	/* verify that rtcp_decode() read the whole buffer */
	TEST_EQUALS(mb->end, mb->pos);

 out:
	mem_deref(mb);
	mem_deref(msg);
	return err;
}
Example #24
0
TEST_DEFINE_TEST(TestCtx, EnumTests)
{
    auto t = Module.GetRootObject<test::IEnumTests>("GetTests");
    if (!t)
    {
        TEST_REPORT_ERROR("EnumTests not implemented!");
        return;
    }

    test::Enum e;
    TEST_EQUALS(e._RawValue(), test::Enum::Value1);
    TEST_EQUALS(e.ToString(), joint::String("Value1"));

    e = test::Enum::Value3;
    TEST_EQUALS(e._RawValue(), test::Enum::Value3);
    TEST_EQUALS(e.ToString(), joint::String("Value3"));

    TEST_IS_TRUE(t->StringRepresentation(test::Enum::Value1).Storage().find("Value1") != std::string::npos);
    TEST_IS_TRUE(t->StringRepresentation(test::Enum::Value3).Storage().find("Value3") != std::string::npos);
    TEST_EQUALS(t->GetNextValueInRing(test::Enum::Value1)._RawValue(), test::Enum::Value2);
    TEST_EQUALS(t->GetNextValueInRing(test::Enum::Value2)._RawValue(), test::Enum::Value3);
    TEST_EQUALS(t->GetNextValueInRing(test::Enum::Value3)._RawValue(), test::Enum::Value4);
    TEST_EQUALS(t->GetNextValueInRing(test::Enum::Value4)._RawValue(), test::Enum::Value1);


    e = test::Enum::Value3;
    auto tcb = Module.GetRootObject<test::IEnumCallbackTests>("GetTests");
    auto cb = Ctx.MakeComponent<joint::IObject, EnumTestsCallback>();
    TEST_EQUALS(tcb->CallbackStringRepresentation(joint::Cast<test::IEnumTests>(cb), e), joint::String("Value3"));
    TEST_EQUALS(tcb->CallbackGetNextValueInRing(joint::Cast<test::IEnumTests>(cb), test::Enum::Value1)._RawValue(), test::Enum::Value2);
    TEST_EQUALS(tcb->CallbackGetNextValueInRing(joint::Cast<test::IEnumTests>(cb), test::Enum::Value2)._RawValue(), test::Enum::Value3);
    TEST_EQUALS(tcb->CallbackGetNextValueInRing(joint::Cast<test::IEnumTests>(cb), test::Enum::Value3)._RawValue(), test::Enum::Value4);
    TEST_EQUALS(tcb->CallbackGetNextValueInRing(joint::Cast<test::IEnumTests>(cb), test::Enum::Value4)._RawValue(), test::Enum::Value1);
}
Example #25
0
TEST_DEFINE_TEST(TestCtx, ArrayTests)
{
    auto t = Module.GetRootObject<test::IArrayTests>("GetTests");
    if (!t)
    {
        TEST_REPORT_ERROR("ArrayTests not implemented!");
        return;
    }

    joint::Array<int32_t> i32_array = t->MakeI32Array(2);
    TEST_EQUALS(i32_array.GetSize(), (size_t)2);
    TEST_EQUALS(i32_array[0], (int32_t)0);
    TEST_THROWS_NOTHING(i32_array.Set(0, 42));
    TEST_THROWS_NOTHING(i32_array.Set(1, 256));
    TEST_EQUALS(i32_array[0], (int32_t)42);
    TEST_EQUALS(i32_array[1], (int32_t)256);

    i32_array = joint::Array<int32_t>(4);
    i32_array.Set(0, 1);
    i32_array.Set(1, 2);
    i32_array.Set(2, 4);
    i32_array.Set(3, 8);
    TEST_EQUALS(t->GetI32Element(i32_array, 0), (int32_t)1);
    TEST_EQUALS(t->GetI32Element(i32_array, 1), (int32_t)2);
    TEST_EQUALS(t->GetI32Element(i32_array, 2), (int32_t)4);
    TEST_EQUALS(t->GetI32Element(i32_array, 3), (int32_t)8);

    t->SetI32Element(i32_array, 0, (int32_t)2);
    t->SetI32Element(i32_array, 1, (int32_t)3);
    t->SetI32Element(i32_array, 2, (int32_t)5);
    t->SetI32Element(i32_array, 3, (int32_t)9);

    TEST_EQUALS(t->GetI32Element(i32_array, 0), (int32_t)2);
    TEST_EQUALS(t->GetI32Element(i32_array, 1), (int32_t)3);
    TEST_EQUALS(t->GetI32Element(i32_array, 2), (int32_t)5);
    TEST_EQUALS(t->GetI32Element(i32_array, 3), (int32_t)9);
}
Example #26
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(coffee_test_process, ev, data)
{
  int fd_write, n, i;
  static int cnt = 0;
  uint8_t buffer[FILE_SIZE];
  clock_time_t now;
  unsigned short now_fine;
  static uint32_t time_start, time_stop;

  printf("###########################################################\n");

  PROCESS_BEGIN();

  printf("process running\n");

  // wait for 5 sec
  etimer_set(&et, CLOCK_SECOND * 5);
  PROCESS_YIELD_UNTIL(etimer_expired(&et));

#if (COFFEE_DEVICE == 6)
  int initialized = 0, i;

  SDCARD_POWER_ON();

  //--- Detecting devices and partitions
  TEST_EQUALS(diskio_detect_devices(), DISKIO_SUCCESS);

  info = diskio_devices();
  for (i = 0; i < DISKIO_MAX_DEVICES; i++) {
    if ((info + i)->type == (DISKIO_DEVICE_TYPE_SD_CARD | DISKIO_DEVICE_TYPE_PARTITION)) {
      info += i;
      initialized = 1;
      break; 
    }
  }
  TEST_EQUALS(initialized, 1);

  diskio_set_default_device(info);
#endif

  printf("fomartting...\n");
  TEST_EQUALS(cfs_coffee_format(), 0);
  //printf("test starting\n");

  do {
    now_fine = clock_time();
    now = clock_seconds();
  } while (now_fine != clock_time());
  time_start = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND;

  while(1) {
    // Shortest possible pause
    PROCESS_PAUSE();

    // Determine the filename
    char b_file[8];
    sprintf(b_file,"%u.b", cnt);

    // Set the file size
    printf("Reserving '%s'...\n", b_file);
    TEST_EQUALS(cfs_coffee_reserve(b_file, FILE_SIZE), 0);

      // And open it
    printf("Opening '%s'...\n", b_file);
    fd_write = cfs_open(b_file, CFS_WRITE);
    TEST_NEQ(fd_write, -1);

    // fill buffer
    for(i=0; i<FILE_SIZE; i++) {
      buffer[i] = cnt % 0xFF;
    }

    // Open was successful, write has to be successful too since the size has been reserved
    printf("Writing'%s'...\n", b_file);
    n = cfs_write(fd_write, buffer, FILE_SIZE);
    cfs_close(fd_write);

    TEST_EQUALS(n, FILE_SIZE);

    printf("%s written\n", b_file);

    if( cnt >= FILES_IN_STORAGE ) {
      int fd_read;

      // Figure out the filename
      char r_file[8];
      sprintf(r_file,"%u.b", cnt - FILES_IN_STORAGE);

      // Open the bundle file
      printf("Reopening '%s'...\n", r_file);
      fd_read = cfs_open(r_file, CFS_READ);
      if(fd_read == -1) {
        // Could not open file
        printf("############# STORAGE: could not open file %s\n", r_file);
        fail();
      }

      memset(buffer, 0, FILE_SIZE);

      // And now read the bundle back from flash
      printf("Reading '%s'...\n", b_file);
      if (cfs_read(fd_read, buffer, FILE_SIZE) == -1){
        printf("############# STORAGE: cfs_read error\n");
        cfs_close(fd_read);
        fail();
      }
      cfs_close(fd_read);

      for(i=0; i<FILE_SIZE; i++) {
        if( buffer[i] != (cnt - FILES_IN_STORAGE) % 0xFF ) {
          printf("############# STORAGE: verify error\n");
          fail();
        }
      }

      if( cfs_remove(r_file) == -1 ) {
        printf("############# STORAGE: unable to remove %s\n", r_file);
        fail();
      }

      printf("%s deleted\n", r_file);
    }

    cnt ++;

    if( cnt >= 10 ) {
      do {
        now_fine = clock_time();
        now = clock_seconds();
      } while (now_fine != clock_time());
      time_stop = ((unsigned long)now)*CLOCK_SECOND + now_fine%CLOCK_SECOND;

      TEST_REPORT("data written", FILE_SIZE*cnt*CLOCK_SECOND, time_stop-time_start, "bytes/s");
      TEST_PASS();
      watchdog_stop();
      while(1);
    }
  }

  PROCESS_END();
}