Esempio n. 1
0
void
st_multimethods_ptr(void)
{
  useclass(Counter);
  usegeneric((gaddTo1)gaddTo1_s, (gaddTo2)gaddTo2_s,
             (gaddTo3)gaddTo3_s, (gaddTo4)gaddTo4_s);

  OBJ cnt = gnew(Counter);
  OBJ one = gincr(gnew(Counter));
  OBJ ret;

  U32 cid = cos_object_id(cnt);
  U32 oid = cos_object_id(one);

  IMP2 gaddTo1_p = cos_method_lookup2((SEL)gaddTo1_s, cid, oid);
  IMP3 gaddTo2_p = cos_method_lookup3((SEL)gaddTo2_s, cid, oid, oid);
  IMP4 gaddTo3_p = cos_method_lookup4((SEL)gaddTo3_s, cid, oid, oid, oid);
  IMP5 gaddTo4_p = cos_method_lookup5((SEL)gaddTo4_s, cid, oid, oid, oid, oid);

  STEST( "multimethod pointer (rank 2)", N, gaddTo1_p((SEL)gaddTo1_s,cnt,one,0,&ret) );
  STEST( "multimethod pointer (rank 3)", N, gaddTo2_p((SEL)gaddTo2_s,cnt,one,one,0,&ret) );
  STEST( "multimethod pointer (rank 4)", N, gaddTo3_p((SEL)gaddTo3_s,cnt,one,one,one,0,&ret) );
  STEST( "multimethod pointer (rank 5)", N, gaddTo4_p((SEL)gaddTo4_s,cnt,one,one,one,one,0,&ret) );
  
  test_assert( gint(cnt) == N+2*N+3*N+4*N );

  grelease(cnt);
  grelease(one);
}
Esempio n. 2
0
File: point.c Progetto: treblih/omfc
int
main(int argc, char *argv[])
{
	$pri(Point) point = (PTR) gnew(Point, 5, 6);
	$do(point, draw);
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 3
0
void
st_methods_ptr(void)
{
  useclass(Counter);
  usegeneric((gincr)gincr_s,
             (gincrBy1)gincrBy1_s, (gincrBy2)gincrBy2_s, (gincrBy3)gincrBy3_s,
             (gincrBy4)gincrBy4_s, (gincrBy5)gincrBy5_s);

  OBJ cnt = gnew(Counter);
  OBJ ret;

  IMP1 gincr_p    = cos_method_lookup1((SEL)gincr_s   , cos_object_id(cnt));
  IMP1 gincrBy1_p = cos_method_lookup1((SEL)gincrBy1_s, cos_object_id(cnt));
  IMP1 gincrBy2_p = cos_method_lookup1((SEL)gincrBy2_s, cos_object_id(cnt));
  IMP1 gincrBy3_p = cos_method_lookup1((SEL)gincrBy3_s, cos_object_id(cnt));
  IMP1 gincrBy4_p = cos_method_lookup1((SEL)gincrBy4_s, cos_object_id(cnt));
  IMP1 gincrBy5_p = cos_method_lookup1((SEL)gincrBy5_s, cos_object_id(cnt));

  gincrBy1_arg_t arg1 = { 1 };
  gincrBy2_arg_t arg2 = { 1,1 };
  gincrBy3_arg_t arg3 = { 1,1,1 };
  gincrBy4_arg_t arg4 = { 1,1,1,1 };
  gincrBy5_arg_t arg5 = { 1,1,1,1,1 };

  STEST( "method pointer (0 argument )", N, gincr_p   ((SEL)gincr_s   ,cnt,0    ,&ret) );
  STEST( "method pointer (1 argument )", N, gincrBy1_p((SEL)gincrBy1_s,cnt,&arg1,&ret) );
  STEST( "method pointer (2 arguments)", N, gincrBy2_p((SEL)gincrBy2_s,cnt,&arg2,&ret) );
  STEST( "method pointer (3 arguments)", N, gincrBy3_p((SEL)gincrBy3_s,cnt,&arg3,&ret) );
  STEST( "method pointer (4 arguments)", N, gincrBy4_p((SEL)gincrBy4_s,cnt,&arg4,&ret) );
  STEST( "method pointer (5 arguments)", N, gincrBy5_p((SEL)gincrBy5_s,cnt,&arg5,&ret) );
  
  test_assert( gint(cnt) == N+N+2*N+3*N+4*N+5*N );

  grelease(cnt);
}
Esempio n. 4
0
void
st_multimethods(void)
{
  useclass(Counter);

  OBJ cnt = gnew(Counter);
  OBJ one = gincr(gnew(Counter));

  STEST( "multimethod (rank 2)", N, gaddTo1(cnt,one) );
  STEST( "multimethod (rank 3)", N, gaddTo2(cnt,one,one) );
  STEST( "multimethod (rank 4)", N, gaddTo3(cnt,one,one,one) );
  STEST( "multimethod (rank 5)", N, gaddTo4(cnt,one,one,one,one) );
  
  test_assert( gint(cnt) == N+2*N+3*N+4*N );
  grelease(cnt);
  grelease(one);
}
Esempio n. 5
0
int main(int argc, char** argv) {

    int status;
    char forking;
    message_t message;
    pid_t pid, cpid;
    ipc_t ipc;
    grid_t grid = gnew();
    
    LOGPID("Using IPC method: %s.\n", IPC_METHOD);
    
    /* Before doing anything else, map data should be loaded! */
    /* (so as to know the number of ants beforehand, at least */
    
	if((status = loadGrid(grid, "configurationFile")) != NO_ERRORS)
	{
		printf("An error occurred while loading the configuration file\n");
		exit(status);
	}
	
    /* This process will act as IPC server/simulation control */
    
    sid = 1;        /* Control has simulation ID 1 */
    pid = getpid(); /* and it's pid, obviously */

    LOGPID("Control process started.\n");    
    ipc = initServer();
    
    /* Good! IPC server working. Let's spawn those ants. */
    
    if (cpid = fork()) {
    
        /* Control code here */        
    	int aux;
    	if((aux = launchControl(ipc, grid)) != NO_ERROR){
    		printf("Simulation fail: %d\n", aux );
    	}else{
    		LOGPID("Simulation ended succesfully!\n");
    	}
    } else {       
    
        /* Ants here */
        do {
            sid++;
            pid = getpid();
            ipc = initClient();
            if (forking = (sid - 1 < grid->antsQuant))
                forking = ((cpid = fork()) == 0); /* Child will keep forking */
        } while (forking);
        
        /* We can do our own stuff now */                  
        status = antLoop(ipc, grid);
        exit(status);
        
    }
    
    freeGrid(grid);
}
Esempio n. 6
0
File: stack.c Progetto: treblih/omfc
	int
main ( int argc, char *argv[] )
{
	$pri(Stack) stk = (PTR) gnew(Stack);
	$do(stk, push, $arg(5));
	printf("%d\n", $do(stk, pop));

	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 7
0
void
st_pxymultimethods(void)
{
  useclass(Counter, Proxy);

  OBJ cnt = gnew(Counter);
  OBJ pxy = gnewWith(Proxy,cnt);
  OBJ one = gincr(gnew(Counter));

  grelease(cnt);

  STEST( "multimethod through proxy (rank 2)", N, gaddTo1(pxy,one) );
  STEST( "multimethod through proxy (rank 3)", N, gaddTo2(pxy,one,one) );
  STEST( "multimethod through proxy (rank 4)", N, gaddTo3(pxy,one,one,one) );
  STEST( "multimethod through proxy (rank 5)", N, gaddTo4(pxy,one,one,one,one) );
  
  test_assert( gint(pxy) == N+2*N+3*N+4*N );
  grelease(pxy);
  grelease(one);
}
Esempio n. 8
0
File: list.c Progetto: treblih/omfc
int
main ( int argc, char *argv[] )
{
	$pri(List) list = (PTR) gnew(List);
	$do(list, add, $arg(2));
	$do(list, add, $arg(6));
	$do(list, add, $arg(61));
	/* $do(list, rem); */

	T x = $do(($pri(Node))$do(list, find_first_nonnull), getter_x);
	
	printf("%d\n", x);
	return EXIT_SUCCESS;
}				/* ----------  end of function main  ---------- */
Esempio n. 9
0
void
st_nextmethods(void)
{
  enum { P = N/2 };
  useclass(MilliCounter);

  OBJ cnt = gnew(MilliCounter);

  STEST( "method + next method (0 argument )", P, gincr(cnt) );
  STEST( "method + next method (1 argument )", P, gincrBy1(cnt,1) );
  STEST( "method + next method (2 arguments)", P, gincrBy2(cnt,1,1) );
  STEST( "method + next method (3 arguments)", P, gincrBy3(cnt,1,1,1) );
  STEST( "method + next method (4 arguments)", P, gincrBy4(cnt,1,1,1,1) );
  STEST( "method + next method (5 arguments)", P, gincrBy5(cnt,1,1,1,1,1) );
  
  test_assert( gint(cnt) == P+P+2*P+3*P+4*P+5*P );
  grelease(cnt);
}
Esempio n. 10
0
void
st_methods(void)
{
  useclass(Counter);

  OBJ cnt = gnew(Counter);

  STEST( "method (0 argument )", N, gincr(cnt) );
  STEST( "method (1 argument )", N, gincrBy1(cnt,1) );
  STEST( "method (2 arguments)", N, gincrBy2(cnt,1,1) );
  STEST( "method (3 arguments)", N, gincrBy3(cnt,1,1,1) );
  STEST( "method (4 arguments)", N, gincrBy4(cnt,1,1,1,1) );
  STEST( "method (5 arguments)", N, gincrBy5(cnt,1,1,1,1,1) );
  
  test_assert( gint(cnt) == N+N+2*N+3*N+4*N+5*N );

  grelease(cnt);
}
Esempio n. 11
0
void
st_memory(void)
{
  enum { P = N/2/sizeof(void*) };
  static OBJ arr[P];
  useclass(Counter, AutoRelease);
  OBJ ar = gnew(AutoRelease);
  size_t sz = gsize(Counter);
  size_t i;
  int lvl;

  // allocator warm up
  for (i = 0; i < P; i++)
    arr[i++] = malloc(sz);

  for (i = 0; i < P; i++)
    free(arr[i++]);

  i = 0;
  STEST( "malloc", P, arr[i++] = malloc(sz) );

  i = 0;
  STEST( "free", P, free(arr[i++]) );

  i = 0;
  STEST( "alloc + init", P, arr[i++] = ginit(galloc(Counter)) );

  i = 0;
  STEST( "retain", P, gretain(arr[i++]) );

  i = 0;
  lvl = cos_logmsg_setLevel(COS_LOGMSG_WARN);
  STEST( "autoRelease", P, gautoRelease(arr[i++]) );
  cos_logmsg_setLevel(lvl);

  i = 0;
  STEST( "release", P, grelease(arr[i++]) );

  STEST( "alloc + init + release", P, grelease(ginit(galloc(Counter))) );

  grelease(ar);
}
Esempio n. 12
0
void
st_pxymethods(void)
{
  useclass(Counter, Proxy);

  OBJ cnt = gnew(Counter);
  OBJ pxy = gnewWith(Proxy,cnt);

  grelease(cnt);

  STEST( "method through proxy (0 argument )", N, gincr(pxy) );
  STEST( "method through proxy (1 argument )", N, gincrBy1(pxy,1) );
  STEST( "method through proxy (2 arguments)", N, gincrBy2(pxy,1,1) );
  STEST( "method through proxy (3 arguments)", N, gincrBy3(pxy,1,1,1) );
  STEST( "method through proxy (4 arguments)", N, gincrBy4(pxy,1,1,1,1) );
  STEST( "method through proxy (5 arguments)", N, gincrBy5(pxy,1,1,1,1,1) );

  test_assert( gint(pxy) == N + N+2*N+3*N+4*N+5*N );
  
  grelease(pxy);
}
Esempio n. 13
0
void
ut_string(void)
{
//  useclass(Array, String);
  useclass(Lesser,Equal,Greater);
  useclass(AutoRelease);
  
  OBJ buf[] = { aStr("toto","tutu","","titi") };
  OBJ srt[] = { aStr("","titi","toto","tutu") };
  OBJ arr;

  OBJ pool = gnew(AutoRelease);

  UTEST_START("String")

    UTEST(gisEqual(aStr(""),aStr("")) == True);
    UTEST(gisEqual(aStr(""),aStr("titi")) == False);
    UTEST(gisEqual(aStr("titi"),aStr("")) == False);

    UTEST(gisEqual(aStr("titi"),aStr("titi")) == True);
    UTEST(gisEqual(aStr("tutu"),aStr("titi")) == False);

    UTEST(gcompare(aStr(""),aStr("")) == Equal);
    UTEST(gcompare(aStr(""),aStr("titi")) == Lesser);
    UTEST(gcompare(aStr("titi"),aStr("")) == Greater);

    UTEST(gcompare(aStr("tata"),aStr("titi")) == Lesser);
    UTEST(gcompare(aStr("titi"),aStr("titi")) == Equal);
    UTEST(gcompare(aStr("tutu"),aStr("titi")) == Greater);

    UTEST(gcompare(aStr("titis"),aStr("tutu")) == Lesser);
    UTEST(gcompare(aStr("tutu"),aStr("titis")) == Greater);
    UTEST(gcompare(aStr("titis"),aStr("titi")) == Greater);
    UTEST(gcompare(aStr("titi"),aStr("titis")) == Lesser);

    arr = aArrayRef(buf, COS_ARRLEN(buf));

    UTEST(gfind(arr, aStr("toto")) != Nil);
    UTEST(gfind(arr, aStr("tutu")) != Nil);
    UTEST(gfind(arr, aStr("titi")) != Nil);
    UTEST(gfind(arr, aStr("tata")) == Nil);
    UTEST(gfind(arr, aStr("titis")) == Nil);
    UTEST(gfind(arr, aStr("totos")) == Nil);
    UTEST(gfind(arr, aStr("tutus")) == Nil);
    UTEST(gfind(arr, aStr("")) != Nil);
    
    UTEST(gfind(arr, aFun(gisEqual, aStr("titi"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("toto"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tutu"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("titis"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("totos"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr("tutus"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr(""), __1)) != Nil);

    gsort(arr, aFun(gcompare,__1,__2));

    UTEST(gisEqual(arr, aArrayRef(srt, COS_ARRLEN(srt))) == True);

    UTEST(gfind(arr, aFun(gcompare, aStr("titi"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("toto"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tutu"), __1)) != Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("titis"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("totos"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr("tutus"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr(""), __1)) != Nil);

    arr = aArrayRef(0, 0);

    UTEST(gfind(arr, aStr("tata")) == Nil);
    UTEST(gfind(arr, aStr("")) == Nil);

    UTEST(gfind(arr, aFun(gisEqual, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gisEqual, aStr(""), __1)) == Nil);

    UTEST(gfind(arr, aFun(gcompare, aStr("tata"), __1)) == Nil);
    UTEST(gfind(arr, aFun(gcompare, aStr(""), __1)) == Nil);

  UTEST_END

  grelease(pool);
}