Beispiel #1
0
/* 57 */
int sio2_func3(int arg)
{
	if (cb3)
		return cb3(arg);

	return 1;
}
/**
 * Test sull'uso dei costruttori della classe cbuffer. In totale creo 5 cbuffer.
*/
void testCostructor(){
	cbuffer<double> cb(10, 1.2); 
	cbuffer<int> cb2(11,3);
	std::cout << "size: "<<cb.get_size()<<" items: "<<cb.get_items()<<" //" << cb << std::endl;
	std::cout << "size: "<<cb2.get_size()<<" items: "<<cb2.get_items()<<" //" << cb2 << std::endl;
	cb=cb2;
	cbuffer<double> cb3(cb2);
	std::cout << "size: "<<cb.get_size()<<" items: "<<cb.get_items()<<" //" << cb << std::endl;
	std::cout << "size: "<<cb3.get_size()<<" items: "<<cb3.get_items()<<" //" << cb3 << std::endl;
	
	cbuffer<char> cb1(5,'a');
	cbuffer<char> cb4(cb1);
	std::cout << "size: "<<cb4.get_size()<<" items: "<<cb4.get_items()<<" //" << cb4 << std::endl;
}
/**
 * Test per verificare il corretto funzionamento della funzione globale check
*/
void testCheck(){
	predicato pred;
	cbuffer<int> cb(10,2);
	cb[0]=1;
	check(cb, pred);
	cbuffer<double> cb1(10,2.5);
	cb1[2]=6;
	check(cb1, pred);
	cbuffer<std::string> cb2(10,"bomber");
	check(cb2, pred);
	cbuffer<char> cb3(10,'x');
	cb3.insert('a');
	cb3[0]='e';
	cb3[6]='u';
	check(cb3,pred);
}
Beispiel #4
0
void TestSymDiv_E2(tmv::DivType dt, PosDefCode pdc)
{
    const int N = 10;

    std::vector<tmv::SymMatrixView<T> > s;
    std::vector<tmv::SymMatrixView<std::complex<T> > > cs;
    MakeSymList(s,cs,pdc);

    tmv::Matrix<T> a1(N,N);
    for (int i=0; i<N; ++i) for (int j=0; j<N; ++j) a1(i,j) = T(1-3*i+j);
    a1.diag().addToAll(T(10)*N);
    a1 /= T(10);
    tmv::Matrix<std::complex<T> > ca1 = a1 * std::complex<T>(3,-4);

    tmv::BandMatrix<T> b1(a1,1,3);
    tmv::BandMatrix<std::complex<T> > cb1(ca1,1,3);

    tmv::BandMatrix<T> b1v = b1.view();
    tmv::BandMatrix<std::complex<T> > cb1v = cb1.view();

#if (XTEST & 2)
    tmv::BandMatrix<T> b3(a1.colRange(0,N-2),1,3);
    tmv::BandMatrix<std::complex<T> > cb3(ca1.colRange(0,N-2),1,3);
    tmv::BandMatrix<T> b4(a1.rowRange(0,N-2),1,3);
    tmv::BandMatrix<std::complex<T> > cb4(ca1.rowRange(0,N-2),1,3);

    tmv::BandMatrix<T> b3v = b3.view();
    tmv::BandMatrix<std::complex<T> > cb3v = cb3.view();
    tmv::BandMatrix<T> b4v = b4.view();
    tmv::BandMatrix<std::complex<T> > cb4v = cb4.view();
#endif

    for(size_t i=START;i<s.size();i++) {
        if (showstartdone)
            std::cout<<"Start loop: i = "<<i<<", si = "<<tmv::TMV_Text(s[i])<<
                "  "<<s[i]<<std::endl;
        tmv::SymMatrixView<T> si = s[i];
        tmv::SymMatrixView<std::complex<T> > csi = cs[i];

        TestMatrixDivArith1(dt,b1v,si,cb1v,csi,"Sym/SquareBandMatrix");
        if (dt == tmv::LU) continue;
#if (XTEST & 2)
        TestMatrixDivArith1(dt,b3v,si,cb3v,csi,"Sym/NonSquareBandMatrix");
        TestMatrixDivArith1(dt,b4v,si,cb4v,csi,"Sym/NonSquareBandMatrix");
#endif
    }
}
// min_capacity test (it is useful to use a debug tool)
void min_capacity_test() {

    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);
    v.push_back(4);
    v.push_back(5);

    cb_space_optimized cb1(capacity_ctrl(10, 10));
    cb_space_optimized cb2(capacity_ctrl(10, 5), 1);
    cb_space_optimized cb3(capacity_ctrl(20, 10), v.begin(), v.end());

    BOOST_CHECK(cb1.size() == 0);
    BOOST_CHECK(cb1.capacity().capacity() == 10);
    BOOST_CHECK(cb1.capacity().min_capacity() == 10);
    BOOST_CHECK(cb2[0] == 1);
    BOOST_CHECK(cb2.size() == 10);
    BOOST_CHECK(cb2.capacity() == 10);
    BOOST_CHECK(cb2.capacity().min_capacity() == 5);
    BOOST_CHECK(cb3[0] == 1);
    BOOST_CHECK(cb3.size() == 5);
    BOOST_CHECK(cb3.capacity() == 20);
    BOOST_CHECK(cb3.capacity().min_capacity() == 10);
    BOOST_CHECK(cb1.capacity().min_capacity() <= cb1.internal_capacity());
    BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
    BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());

    cb2.erase(cb2.begin() + 2, cb2.end());

    BOOST_CHECK(cb2.size() == 2);
    BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());

    cb2.clear();
    cb3.clear();

    BOOST_CHECK(cb2.empty());
    BOOST_CHECK(cb3.empty());
    BOOST_CHECK(cb2.capacity().min_capacity() <= cb2.internal_capacity());
    BOOST_CHECK(cb3.capacity().min_capacity() <= cb3.internal_capacity());
}
/**
 * Test per verificare la corretta esecuzione di vari metodi fondamentali. (utilizzo
 * di stampa come procedura d'appoggio).
*/
void testValueGetSetOperator(){
	cbuffer<int> cb1(5);
	cbuffer<float> cb2(4,2.2);
	cbuffer<std::string> cb3(3,"stringa");
	std::cout << "test get_size() e get_items(): " << std::endl;
	std::cout << "cb1 size: " << cb1.get_size() << std::endl;
	std::cout << "cb2 size: " << cb2.get_size() << std::endl;
	std::cout << "cb3 size: " << cb3.get_size() << std::endl;
	std::cout << "cb1 items: " << cb1.get_items() << std::endl;
	std::cout << "cb2 items: " << cb2.get_items() << std::endl;
	std::cout << "cb3 items: " << cb3.get_items() << std::endl;
	
	std::cout << "test get_cbuffer(size_type) e set_cbuffer(size_type, const &T):" << std::endl;
	cb2.set_cbuffer(3, 4);
	std::cout << "cb2[3] set 4 " << std::endl;
	std::cout << "cb2[3] get: " << cb2.get_cbuffer(3) << std::endl;
	
	std::cout << "test T& value(size_type index):" << std::endl;
	cb3.value(0)="fiorellino";
	std::cout << "scrittura cb3.value(0)"<< std::endl;
	std::cout << "lettura cb3.value(0)= " << cb3.value(0) << std::endl;
	
	std::cout << "test operator[]" << std::endl;
	cb3[2]="alberello";
	std::cout << "scrittura cb3[2] " << std::endl;
	std::cout << "lettra cb3[2] " << cb3[2] << std::endl;
	
	std::cout << "stampa(const cbuffer<int>)" << std::endl;
	cbuffer<int> cb4(6);
	cb4.insert(1);
	cb4.insert(2);
	cb4.insert(3);
	cb4.insert(4);
	std::cout << cb4 << std::endl;
	stampa(cb4);
}
extern "C" int main(int argc, char *argv[]) {
	Callback cb("notify", &cbFunc, NULL);

	checkpointNext("Objects:");
	testNotify("  Normal", cb, 0x1337);
	testNotify("  NULL", 0, 0x1337);
	testNotify("  Invalid", 0xDEADBEEF, 0x1337);
	cb.Delete();
	testNotify("  Deleted", cb, 0x1337);

	cb.Create("notify", &cbFunc, NULL);
	checkpointNext("Values:");
	testNotify("  Zero", cb, 0);
	testNotify("  DEADBEEF", cb, 0xDEADBEEF);

	checkpointNext("Notifies:");
	int result = 0;
	for (int i = 0; i < 10000; ++i) {
		result = sceKernelNotifyCallback(cb, 1);
		if (result != 0) {
			checkpoint("  Failed at %d: %08x", i, result);
			break;
		}
	}
	if (result == 0) {
		checkpoint("  10000 notifies: OK");
	}

	checkpoint("sceKernelDelayThreadCB: %08x", sceKernelDelayThreadCB(1000));

	checkpointNext("Different thread:");
	{
		CallbackSleeper waiter1("better priority sleeping thread", 0x10);
		CallbackSleeper waiter2("worse priority sleeping thread", 0x30);
		sceKernelDelayThread(1000);
		sceKernelNotifyCallback(waiter1.callbackID(), 0x1337);
		sceKernelNotifyCallback(waiter2.callbackID(), 0x1337);
		sceKernelDelayThread(1000);
	}

	checkpointNext("Return value:");
	{
		CallbackSleeper waiter("sleeping thread");
		waiter.setReturn(0x1337);
		sceKernelDelayThread(1000);
		testNotify("  Notify #1", waiter.callbackID(), 0x1337);
		sceKernelDelayThread(1000);
		testNotify("  Notify #2", waiter.callbackID(), 0x1337);
		sceKernelDelayThread(1000);
	}

	checkpointNext("Recursion:");
	{
		SelfNotifier waiter("sleeping thread");
		sceKernelDelayThread(1000);
		testNotify("  Notify #1", waiter.callbackID(), 0x1337);
		sceKernelDelayThread(1000);
	}

	checkpointNext("Mixing types:");
	checkpoint("  scePowerRegisterCallback (causes notify): %08x", scePowerRegisterCallback(0, cb));
	testNotify("  Manual notify", cb, 0x1337);
	checkpoint("  sceKernelDelayThreadCB: %08x", sceKernelDelayThreadCB(1000));

	checkpointNext("Order:");
	Callback cb1("notify1", &cbFunc, (void *)0xABC00001);
	Callback cb2("notify2", &cbFunc, (void *)0xABC00002);
	Callback cb3("notify3", &cbFunc, (void *)0xABC00003);
	testNotify("  Notify cb #2", cb2, 0xDEF00001);
	testNotify("  Notify cb #1", cb1, 0xDEF00002);
	testNotify("  Notify cb #3", cb3, 0xDEF00003);
	checkpoint("  sceKernelCheckCallback: %08x", sceKernelCheckCallback());

	return 0;
}