Пример #1
0
void test_framework() {
	duk_context* ctx = duk_create_heap_default();

	test_eval(ctx, "var test = 2;");
	test_eval_expect(ctx, "test", 2);
	test_eval(ctx, "var str = 'Butts';");
	test_eval_expect(ctx, "str", "Butts");
	test_eval_expect_error(ctx, "#($*)@*(");
	test_assert(true);

	duk_destroy_heap(ctx);

	std::cout << "Framework OK" << std::endl;
}
Пример #2
0
EnvTest( long version, GlobalFunc *global, LWLayoutGeneric *local,
   void *serverData )
{
   LWItemID id;
   LWChanGroupID group;
   LWChannelID chan;

   if ( version != LWLAYOUTGENERIC_VERSION ) return AFUNC_BADVERSION;

   if ( !get_globals( global ))
      return AFUNC_BADGLOBAL;

   id = iteminfo->first( LWI_CAMERA, NULL );
   group = iteminfo->chanGroup( id );
   chan = chinfo->nextChannel( group, NULL );
   while ( chan ) {
      if ( !strcmp( chinfo->channelName( chan ), "Position.X" )) break;
      chan = chinfo->nextChannel( group, chan );
   }

   if ( !chan ) {
      msgf->info( "Couldn't find Position.X", NULL );
      return AFUNC_OK;
   }

   test_eval( chan );

   return AFUNC_OK;
}
Пример #3
0
int main(int argc, char ** argv)
{
    char *args[50];
    char lpar[3] = "-L";
    char wsname[16] = "/tmp/libgap.ws"; /* the name must match the one used in wscreate.c */
    memcpy(args, argv, argc*sizeof(char*));
    args[argc] = lpar;
    args[argc+1] = wsname;
    args[argc+2] = NULL;
    GAP_Initialize(argc+2, args, environ, 0L, 0L);
    printf("# looking at saved stuff...\n");
    test_eval("g;");
    test_eval("a;");
    test_eval("b;");
    test_eval("[a^2, a^2, b*a];");
    test_eval("Order(h);");
    printf("# done\n");
    return 0;
}
Пример #4
0
int main(void)
{
	//print_masks();
	test_masks();
	test_eval();
	test_eval2();
	test_eval3();
	test_format();
	test_calcN2();
	test_calcRunLength();
	test_calcN1N3();

	report();

	QRspec_clearCache();

	return 0;
}
Пример #5
0
int main(int argc, char ** argv)
{
    GAP_Initialize(argc, argv, 0, 0, 1);
    test_eval("g:=FreeGroup(2);");
    test_eval("a:=g.1;");
    test_eval("b:=g.2;");
    test_eval("lis:=[a^2, a^2, b*a];");
    test_eval("h:=g/lis;");
    /* TODO: use unique temporary filename to avoid a race */
    test_eval("SaveWorkspace(\"/tmp/libgap.ws\");\n");
    printf("# done\n");
    return 0;
}
Пример #6
0
int main()
{
   test_symbol();
   test_integer();
   test_cell();
   test_list();
   test_environment();
   test_eval();
   test_plus_integer();
   test_begin();
   test_string();
   test_tokenize();
   test_newlispobj();
   test_expandreadmacro();
   test_read_tokens();
   test_macro();
   test_equal();
   test_cond();

   return 0;
}
Пример #7
0
int test_search(Position &pos, int alpha, int beta, int depth) {
	
	if(depth == 0) return test_eval(pos);
	bool bSearchPv = true;
	int score;
	
	MoveStack mlist[MAX_MOVES];
	StateInfo st;
	Move m;

	// Generate all legal moves
	MoveStack* last = generate<MV_LEGAL>(pos, mlist);
	
	if (mlist == last) {
		return -100000;
	}
	
	for (MoveStack* cur = mlist; cur != last; cur++) {
		m = cur->move;
		pos.do_move(m, st);
		if (bSearchPv) {
			score = -test_search(pos, -beta, -alpha, depth - 1);
		} else {
			score = -test_search(pos, -alpha-1, -alpha, depth - 1);
			if (score > alpha) // in fail-soft ... && score < beta ) is common
				score = -test_search(pos, -beta, -alpha, depth - 1); // re-search
		}
		pos.undo_move(m);
		if(score >= beta)
			return beta;   // fail-hard beta-cutoff
		if(score > alpha) {
			alpha = score; // alpha acts like max in MiniMax
		}
		bSearchPv = false;
	}
	
	
	
	return alpha; // fail-hard
}
Пример #8
0
void test_procedure()
{
    if (!uci.engine_initialized)
        init_engine(position);

    assert(test_bitscan());
	assert(test_bittwiddles());
    assert(test_fen());
    assert(test_genmove());
    assert(test_make_unmake());
    assert(test_hash());
    assert(test_eval());
    assert(test_capture_gen());
    assert(test_check_gen());
    assert(test_alt_move_gen());
    assert(test_see());
    assert(test_position());
	assert(test_hash_table());
	assert(test_ep_capture());
	assert(test_book());
    test_search();
}
Пример #9
0
static int
main_init(int argc, const char *argv[], Source **sp, struct block **lp)
{
	int argi, i;
	Source *s = NULL;
	struct block *l;
	unsigned char restricted_shell, errexit, utf_flag;
	char *cp;
	const char *ccp, **wp;
	struct tbl *vp;
	struct stat s_stdin;
#if !defined(_PATH_DEFPATH) && defined(_CS_PATH)
	ssize_t k;
#endif

#if defined(MKSH_EBCDIC) || defined(MKSH_FAUX_EBCDIC)
	ebcdic_init();
#endif
	set_ifs(TC_IFSWS);

#ifdef __OS2__
	os2_init(&argc, &argv);
#endif

	/* do things like getpgrp() et al. */
	chvt_reinit();

	/* make sure argv[] is sane, for weird OSes */
	if (!*argv) {
		argv = empty_argv;
		argc = 1;
	}
	kshname = argv[0];

	/* initialise permanent Area */
	ainit(&aperm);
	/* max. name length: -2147483648 = 11 (+ NUL) */
	vtemp = alloc(offsetof(struct tbl, name[0]) + 12, APERM);

	/* set up base environment */
	env.type = E_NONE;
	ainit(&env.area);
	/* set up global l->vars and l->funs */
	newblock();

	/* Do this first so output routines (eg, errorf, shellf) can work */
	initio();

	/* determine the basename (without '-' or path) of the executable */
	ccp = kshname;
	goto begin_parsing_kshname;
	while ((i = ccp[argi++])) {
		if (mksh_cdirsep(i)) {
			ccp += argi;
 begin_parsing_kshname:
			argi = 0;
			if (*ccp == '-')
				++ccp;
		}
	}
	if (!*ccp)
		ccp = empty_argv[0];

	/*
	 * Turn on nohup by default. (AT&T ksh does not have a nohup
	 * option - it always sends the hup).
	 */
	Flag(FNOHUP) = 1;

	/*
	 * Turn on brace expansion by default. AT&T kshs that have
	 * alternation always have it on.
	 */
	Flag(FBRACEEXPAND) = 1;

	/*
	 * Turn on "set -x" inheritance by default.
	 */
	Flag(FXTRACEREC) = 1;

	/* define built-in commands and see if we were called as one */
	ktinit(APERM, &builtins,
	    /* currently up to 54 builtins: 75% of 128 = 2^7 */
	    7);
	for (i = 0; mkshbuiltins[i].name != NULL; i++)
		if (!strcmp(ccp, builtin(mkshbuiltins[i].name,
		    mkshbuiltins[i].func)))
			Flag(FAS_BUILTIN) = 1;

	if (!Flag(FAS_BUILTIN)) {
		/* check for -T option early */
		argi = parse_args(argv, OF_FIRSTTIME, NULL);
		if (argi < 0)
			return (1);

#if defined(MKSH_BINSHPOSIX) || defined(MKSH_BINSHREDUCED)
		/* are we called as -sh or /bin/sh or so? */
		if (!strcmp(ccp, "sh" MKSH_EXE_EXT)) {
			/* either also turns off braceexpand */
#ifdef MKSH_BINSHPOSIX
			/* enable better POSIX conformance */
			change_flag(FPOSIX, OF_FIRSTTIME, true);
#endif
#ifdef MKSH_BINSHREDUCED
			/* enable kludge/compat mode */
			change_flag(FSH, OF_FIRSTTIME, true);
#endif
		}
#endif
	}

	initvar();

	inittraps();

	coproc_init();

	/* set up variable and command dictionaries */
	ktinit(APERM, &taliases, 0);
	ktinit(APERM, &aliases, 0);
#ifndef MKSH_NOPWNAM
	ktinit(APERM, &homedirs, 0);
#endif

	/* define shell keywords */
	initkeywords();

	init_histvec();

	/* initialise tty size before importing environment */
	change_winsz();

#ifdef _PATH_DEFPATH
	def_path = _PATH_DEFPATH;
#else
#ifdef _CS_PATH
	if ((k = confstr(_CS_PATH, NULL, 0)) > 0 &&
	    confstr(_CS_PATH, cp = alloc(k + 1, APERM), k + 1) == k + 1)
		def_path = cp;
	else
#endif
		/*
		 * this is uniform across all OSes unless it
		 * breaks somewhere hard; don't try to optimise,
		 * e.g. add stuff for Interix or remove /usr
		 * for HURD, because e.g. Debian GNU/HURD is
		 * "keeping a regular /usr"; this is supposed
		 * to be a sane 'basic' default PATH
		 */
		def_path = MKSH_UNIXROOT "/bin" MKSH_PATHSEPS
		    MKSH_UNIXROOT "/usr/bin" MKSH_PATHSEPS
		    MKSH_UNIXROOT "/sbin" MKSH_PATHSEPS
		    MKSH_UNIXROOT "/usr/sbin";
#endif

	/*
	 * Set PATH to def_path (will set the path global variable).
	 * (import of environment below will probably change this setting).
	 */
	vp = global(TPATH);
	/* setstr can't fail here */
	setstr(vp, def_path, KSH_RETURN_ERROR);

#ifndef MKSH_NO_CMDLINE_EDITING
	/*
	 * Set edit mode to emacs by default, may be overridden
	 * by the environment or the user. Also, we want tab completion
	 * on in vi by default.
	 */
	change_flag(FEMACS, OF_SPECIAL, true);
#if !MKSH_S_NOVI
	Flag(FVITABCOMPLETE) = 1;
#endif
#endif

	/* import environment */
	init_environ();

	/* override default PATH regardless of environment */
#ifdef MKSH_DEFPATH_OVERRIDE
	vp = global(TPATH);
	setstr(vp, MKSH_DEFPATH_OVERRIDE, KSH_RETURN_ERROR);
#endif

	/* for security */
	typeset(TinitIFS, 0, 0, 0, 0);

	/* assign default shell variable values */
	typeset("PATHSEP=" MKSH_PATHSEPS, 0, 0, 0, 0);
	substitute(initsubs, 0);

	/* Figure out the current working directory and set $PWD */
	vp = global(TPWD);
	cp = str_val(vp);
	/* Try to use existing $PWD if it is valid */
	set_current_wd((mksh_abspath(cp) && test_eval(NULL, TO_FILEQ, cp,
	    Tdot, true)) ? cp : NULL);
	if (current_wd[0])
		simplify_path(current_wd);
	/* Only set pwd if we know where we are or if it had a bogus value */
	if (current_wd[0] || *cp)
		/* setstr can't fail here */
		setstr(vp, current_wd, KSH_RETURN_ERROR);

	for (wp = initcoms; *wp != NULL; wp++) {
		c_builtin(wp);
		while (*wp != NULL)
			wp++;
	}
	setint_n(global("OPTIND"), 1, 10);

	kshuid = getuid();
	kshgid = getgid();
	kshegid = getegid();

	safe_prompt = ksheuid ? "$ " : "# ";
	vp = global("PS1");
	/* Set PS1 if unset or we are root and prompt doesn't contain a # */
	if (!(vp->flag & ISSET) ||
	    (!ksheuid && !strchr(str_val(vp), '#')))
		/* setstr can't fail here */
		setstr(vp, safe_prompt, KSH_RETURN_ERROR);
	setint_n((vp = global("BASHPID")), 0, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("PGRP")), (mksh_uari_t)kshpgrp, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("PPID")), (mksh_uari_t)kshppid, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("USER_ID")), (mksh_uari_t)ksheuid, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("KSHUID")), (mksh_uari_t)kshuid, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("KSHEGID")), (mksh_uari_t)kshegid, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("KSHGID")), (mksh_uari_t)kshgid, 10);
	vp->flag |= INT_U;
	setint_n((vp = global("RANDOM")), rndsetup(), 10);
	vp->flag |= INT_U;
	setint_n((vp_pipest = global("PIPESTATUS")), 0, 10);

	/* Set this before parsing arguments */
	Flag(FPRIVILEGED) = (kshuid != ksheuid || kshgid != kshegid) ? 2 : 0;

	/* this to note if monitor is set on command line (see below) */
#ifndef MKSH_UNEMPLOYED
	Flag(FMONITOR) = 127;
#endif
	/* this to note if utf-8 mode is set on command line (see below) */
	UTFMODE = 2;

	if (!Flag(FAS_BUILTIN)) {
		argi = parse_args(argv, OF_CMDLINE, NULL);
		if (argi < 0)
			return (1);
	}

	/* process this later only, default to off (hysterical raisins) */
	utf_flag = UTFMODE;
	UTFMODE = 0;

	if (Flag(FAS_BUILTIN)) {
		/* auto-detect from environment variables, always */
		utf_flag = 3;
	} else if (Flag(FCOMMAND)) {
		s = pushs(SSTRINGCMDLINE, ATEMP);
		if (!(s->start = s->str = argv[argi++]))
			errorf(Tf_optfoo, "", "", 'c', Treq_arg);
		while (*s->str) {
			if (ctype(*s->str, C_QUOTE))
				break;
			s->str++;
		}
		if (!*s->str)
			s->flags |= SF_MAYEXEC;
		s->str = s->start;
#ifdef MKSH_MIDNIGHTBSD01ASH_COMPAT
		/* compatibility to MidnightBSD 0.1 /bin/sh (kludge) */
		if (Flag(FSH) && argv[argi] && !strcmp(argv[argi], "--"))
			++argi;
#endif
		if (argv[argi])
			kshname = argv[argi++];
	} else if (argi < argc && !Flag(FSTDIN)) {
		s = pushs(SFILE, ATEMP);
#ifdef __OS2__
		/*
		 * A bug in OS/2 extproc (like shebang) handling makes
		 * it not pass the full pathname of a script, so we need
		 * to search for it. This changes the behaviour of a
		 * simple "mksh foo", but can't be helped.
		 */
		s->file = argv[argi++];
		if (search_access(s->file, X_OK) != 0)
			s->file = search_path(s->file, path, X_OK, NULL);
		if (!s->file || !*s->file)
			s->file = argv[argi - 1];
#else
		s->file = argv[argi++];
#endif
		s->u.shf = shf_open(s->file, O_RDONLY, 0,
		    SHF_MAPHI | SHF_CLEXEC);
		if (s->u.shf == NULL) {
			shl_stdout_ok = false;
			warningf(true, Tf_sD_s, s->file, cstrerror(errno));
			/* mandated by SUSv4 */
			exstat = 127;
			unwind(LERROR);
		}
		kshname = s->file;
	} else {
		Flag(FSTDIN) = 1;
		s = pushs(SSTDIN, ATEMP);
		s->file = "<stdin>";
		s->u.shf = shf_fdopen(0, SHF_RD | can_seek(0),
		    NULL);
		if (isatty(0) && isatty(2)) {
			Flag(FTALKING) = Flag(FTALKING_I) = 1;
			/* The following only if isatty(0) */
			s->flags |= SF_TTY;
			s->u.shf->flags |= SHF_INTERRUPT;
			s->file = NULL;
		}
	}

	/* this bizarreness is mandated by POSIX */
	if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
	    Flag(FTALKING))
		reset_nonblock(0);

	/* initialise job control */
	j_init();
	/* do this after j_init() which calls tty_init_state() */
	if (Flag(FTALKING)) {
		if (utf_flag == 2) {
#ifndef MKSH_ASSUME_UTF8
			/* auto-detect from locale or environment */
			utf_flag = 4;
#else /* this may not be an #elif */
#if MKSH_ASSUME_UTF8
			utf_flag = 1;
#else
			/* always disable UTF-8 (for interactive) */
			utf_flag = 0;
#endif
#endif
		}
#ifndef MKSH_NO_CMDLINE_EDITING
		x_init();
#endif
	}

#ifdef SIGWINCH
	sigtraps[SIGWINCH].flags |= TF_SHELL_USES;
	setsig(&sigtraps[SIGWINCH], x_sigwinch,
	    SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
#endif

	l = e->loc;
	if (Flag(FAS_BUILTIN)) {
		l->argc = argc;
		l->argv = argv;
		l->argv[0] = ccp;
	} else {
		l->argc = argc - argi;
		/*
		 * allocate a new array because otherwise, when we modify
		 * it in-place, ps(1) output changes; the meaning of argc
		 * here is slightly different as it excludes kshname, and
		 * we add a trailing NULL sentinel as well
		 */
		l->argv = alloc2(l->argc + 2, sizeof(void *), APERM);
		l->argv[0] = kshname;
		memcpy(&l->argv[1], &argv[argi], l->argc * sizeof(void *));
		l->argv[l->argc + 1] = NULL;
		getopts_reset(1);
	}

	/* divine the initial state of the utf8-mode Flag */
	ccp = null;
	switch (utf_flag) {

	/* auto-detect from locale or environment */
	case 4:
#if HAVE_SETLOCALE_CTYPE
		ccp = setlocale(LC_CTYPE, "");
#if HAVE_LANGINFO_CODESET
		if (!isuc(ccp))
			ccp = nl_langinfo(CODESET);
#endif
		if (!isuc(ccp))
			ccp = null;
#endif
		/* FALLTHROUGH */

	/* auto-detect from environment */
	case 3:
		/* these were imported from environ earlier */
		if (ccp == null)
			ccp = str_val(global("LC_ALL"));
		if (ccp == null)
			ccp = str_val(global("LC_CTYPE"));
		if (ccp == null)
			ccp = str_val(global("LANG"));
		UTFMODE = isuc(ccp);
		break;

	/* not set on command line, not FTALKING */
	case 2:
	/* unknown values */
	default:
		utf_flag = 0;
		/* FALLTHROUGH */

	/* known values */
	case 1:
	case 0:
		UTFMODE = utf_flag;
		break;
	}

	/* Disable during .profile/ENV reading */
	restricted_shell = Flag(FRESTRICTED);
	Flag(FRESTRICTED) = 0;
	errexit = Flag(FERREXIT);
	Flag(FERREXIT) = 0;

	/*
	 * Do this before profile/$ENV so that if it causes problems in them,
	 * user will know why things broke.
	 */
	if (!current_wd[0] && Flag(FTALKING))
		warningf(false, "can't determine current directory");

	if (Flag(FLOGIN))
		include(MKSH_SYSTEM_PROFILE, 0, NULL, true);
	if (!Flag(FPRIVILEGED)) {
		if (Flag(FLOGIN))
			include(substitute("$HOME/.profile", 0), 0, NULL, true);
		if (Flag(FTALKING)) {
			cp = substitute("${ENV:-" MKSHRC_PATH "}", DOTILDE);
			if (cp[0] != '\0')
				include(cp, 0, NULL, true);
		}
	} else {
		include(MKSH_SUID_PROFILE, 0, NULL, true);
		/* turn off -p if not set explicitly */
		if (Flag(FPRIVILEGED) != 1)
			change_flag(FPRIVILEGED, OF_INTERNAL, false);
	}

	if (restricted_shell) {
		c_builtin(restr_com);
		/* After typeset command... */
		Flag(FRESTRICTED) = 1;
	}
	Flag(FERREXIT) = errexit;

	if (Flag(FTALKING) && s)
		hist_init(s);
	else
		/* set after ENV */
		Flag(FTRACKALL) = 1;

	alarm_init();

	*sp = s;
	*lp = l;
	return (0);
}
Пример #10
0
static int
ptest_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
    int do_eval)
{
	return test_eval(te, op, opnd1, opnd2, do_eval);
}
Пример #11
0
int test5(){
    return test_eval(3);
}
Пример #12
0
int test3(){
    return test_eval(0);
}
Пример #13
0
int test4(){
    return test_eval(1);
}
Пример #14
0
void test_eval_expect(duk_context* ctx, const char* code, int expected) {
	test_eval(ctx, code);
	int result = duk_require_int(ctx, -1);
	test_assert(result == expected);
	duk_pop(ctx);
}
Пример #15
0
/*
E' una funzione che serve a contenere i vari test per il debugging di Mizar
*/
void test() {
	char input[256];
	char c = 0, exit, dep;
	exit = 1;
	printf("============\n");
	printf("TESTING MODE\n");
	printf("============\n");

	do {
			puts("\nType quit to return to main menu\noptions: bench, check, eval, order, perf, perft, quit\n");
			printf("Mizar> ");
			scanf("%s", input);

			if (!strcmp(input, "quit"))
				c = 0;

			if (!strcmp(input, "perf"))
				c = 1;

			if (!strcmp(input, "check"))
				c = 2;

			if (!strcmp(input, "perft"))
				c = 3;

			if (!strcmp(input, "bench"))
				c = 4;

			if (!strcmp(input, "order"))
				c = 5;

			if (!strcmp(input, "eval"))
				c = 6;



			switch (c) {
					case 0:
						exit = 0;
						break;
					case 1:
						perf_gen();
						break;
					case 2:
						check_correct();
						break;
					case 3:

						while (1) {
								printf("depth(0=quit)?:");
								scanf("%d", &dep);

								if (dep == 0)
									break;

								perft(dep);
								}

						break;
					case 4:
						bench();
						break;
					case 5:
						order();
						break;
					case 6:
						test_eval();
						break;
					default:
						puts("That is not one of the listed options.");

					}

			}

	while (exit);
	}
Пример #16
0
void zeromq_thread() {
	{
		void* objectContext = zmq_ctx_new();
		void* objectSocket = zmq_socket(objectContext, ZMQ_PAIR);
		
		{
			char charZeromq[1024] = { };
			
			sprintf(charZeromq, "tcp://localhost:%d", main_intZeromq);
			
			if (zmq_connect(objectSocket, charZeromq) == -1) {
				printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
			}
		}
		
		{
			zeromq_objectSocket = objectSocket;
		}
		
		{
			void* objectMonitor = zmq_socket(objectContext, ZMQ_PAIR);
			
			{
				if (zmq_socket_monitor(objectSocket, "inproc://minichess-zeromq-monitor", ZMQ_EVENT_ALL) == -1) {
					printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
				}
				
				if (zmq_connect(objectMonitor, "inproc://minichess-zeromq-monitor") == -1) {
					printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
				}
			}
			
			{
				do {
					int intEventspecifier = 0;
					int intEventvalue = 0;
					char charEventaddress[256] = { };
					
					#if (ZMQ_VERSION_MAJOR == 3)
						{
							zmq_msg_t objectMessage = { };
							
							zmq_msg_init(&objectMessage);
							
							if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) {
								printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
							}
							
							zmq_event_t objectEvent = { };
							
							memcpy(&objectEvent, zmq_msg_data(&objectMessage), sizeof(objectEvent));
							
							intEventspecifier = objectEvent.event;
							intEventvalue = 0
							charEventaddress[0] = '\0';
							
							zmq_msg_close(&objectMessage);
						}
						
					#elif (ZMQ_VERSION_MAJOR == 4)
						{
							zmq_msg_t objectMessage = { };
							
							zmq_msg_init(&objectMessage);
							
							if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) {
								printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
							}
							
							uint8_t* intData = (uint8_t*) (zmq_msg_data(&objectMessage));
							
							intEventspecifier = *(uint16_t*) (intData + 0);
							intEventvalue = *(uint32_t*) (intData + 2);
							
							zmq_msg_close(&objectMessage);
						}
						
						{
							zmq_msg_t objectMessage = { };
							
							zmq_msg_init(&objectMessage);
							
							if (zmq_recvmsg(objectMonitor, &objectMessage, 0) == -1) {
								printf("zeromq: %s\n", zmq_strerror(zmq_errno()));
							}
							
							charEventaddress[0] = '\0';
							
							zmq_msg_close(&objectMessage);
						}
						
					#endif
					
					{
						if (intEventspecifier == ZMQ_EVENT_CONNECTED) {
							{
								zeromq_boolConnected = true;
								
								webserver_broadcast("zeromq_status", NULL);
							}
							
							{
								cJSON* objectOut = cJSON_CreateObject();
								cJSON* objectIn = NULL;
								
								{
									cJSON_AddStringToObject(objectOut, "strFunction", "ping");
								}
								
								{
									zeromq_send(objectOut);
									
									objectIn = zeromq_recv();
								}
								
								{
									strcpy(zeromq_charClient, cJSON_GetObjectItem(objectIn, "strOut")->valuestring);
									
									webserver_broadcast("zeromq_name", NULL);
								}
								
								cJSON_Delete(objectOut);
								cJSON_Delete(objectIn);
							}
							
							{
								printf("zeromq: connected to %s\n", zeromq_charClient);
							}
							
						} else if (intEventspecifier == ZMQ_EVENT_DISCONNECTED) {
							{
								zeromq_boolConnected = false;
								
								webserver_broadcast("zeromq_status", NULL);
							}
							
							{
								printf("zeromq: disconnected from %s\n", zeromq_charClient);
							}
							
						}
					}
					
					{
						if (intEventspecifier == ZMQ_EVENT_CONNECTED) {
							int intTest = 0;
							
							if (intTest > 0) {
								setbuf(stdout, NULL);
							}
							
							if (intTest > 0) {
								printf("test_board: ");
								printf("%d\n", test_board());
							}
							
							if (intTest > 1) {
								printf("test_winner: ");
								printf("%d\n", test_winner());
							}
							
							if (intTest > 2) {
								printf("test_isValid: ");
								printf("%d\n", test_isValid());
							}
							
							if (intTest > 3) {
								printf("test_isEnemy: ");
								printf("%d\n", test_isEnemy());
							}
							
							if (intTest > 4) {
								printf("test_isOwn: ");
								printf("%d\n", test_isOwn());
							}
							
							if (intTest > 5) {
								printf("test_isNothing: ");
								printf("%d\n", test_isNothing());
							}
							
							if (intTest > 6) {
								printf("test_eval: ");
								printf("%d\n", test_eval());
							}
							
							if (intTest > 7) {
								printf("test_moves: ");
								printf("%d\n", test_moves());
							}
							
							if (intTest > 8) {
								printf("test_move: ");
								printf("%d\n", test_move());
							}
							
							if (intTest > 9) {
								printf("test_undo: ");
								printf("%d\n", test_undo());
							}
							
							if (intTest > 10) {
								printf("test_movesShuffled: ");
								printf("%d\n", test_movesShuffled());
							}
							
							if (intTest > 11) {
								printf("test_movesEvaluated: ");
								printf("%d\n", test_movesEvaluated());
							}
							
							if (intTest > 12) {
								printf("test_moveRandom: ");
								printf("%d\n", test_moveRandom());
							}
							
							if (intTest > 13) {
								printf("test_moveGreedy: ");
								printf("%d\n", test_moveGreedy());
							}
							
							if (intTest > 14) {
								printf("test_moveNegamax: ");
								printf("%d\n", test_moveNegamax());
							}
							
							if (intTest > 15) {
								printf("test_moveAlphabeta: ");
								printf("%d\n", test_moveAlphabeta());
							}
						}
					}
				} while (pthread_mutex_trylock(&zeromq_objectRunning) != 0);
				
				pthread_mutex_unlock(&zeromq_objectRunning);
			}
			
			zmq_close(objectMonitor);
		}
		
		zmq_close(objectSocket);
		zmq_ctx_destroy(objectContext);
	}
}
Пример #17
0
int test_eval(int type){
    //test1();
    //    Object *o=p.parse("((A) B C)");
    //    o->dprint();
    //    o->car()->dprint();
    //    o->cdr()->car()->dprint();
    //    o->cdr()->cdr()->dprint();
    Object::init();
    Parser p;
    Object *env;
    char *test_primop="(/ (+ (+ 1 2) (+ 3)  (+ 4 (+ 1 2)) (+ 1 2) (- 5 3) (* 19 2 (+ 1 3))) 3)";
    char *test_lambda="((lambda (a b c) (+ 1 a b c)) 2 3 4)";
    char *test_lambda2="(+ ((lambda (a b c) (+ 1 a b c)) 2 3 4) ((lambda (a b c) (+ 1 a b c)) 2 1 1114))";
    char *test_define="(define x 100)";
    char *test_define2="(define f (lambda (x) (+ 1 x)))";
    char *test_define3="(define (f x y) (+ 1 x y))";
    char *test_if="(if (= 12 13) 1 2)";
    char *test_car="(car '(a b c d))";
    char *test_cdr="(cdr '(a b c d))";
    char *test_cons="(cons '(a)  'c))";
    char *test_cons2="(car (cdr (car (cons (cons '(a b c d e f g) '(c d e f g)) '(aaaa bbbbb cccc)))))";
    char *test_define_set="(define x nil)";
    char *test_setb="(set! x '(a b c d e f))";
    char *test_setcar="(cdr x)";
    char *test_begin="(begin (+ 1 2) (+ 3 4) (+ 9 8))";
    
    char *test_mix="(define add3 (lambda (x) (+ x 3)))";
    char *test_mix1=" (define f1 (+ 1))";
    char *test_mix2="(begin  f1 add3 (add3 10) )";
    char *test_gt="(> 10 2)";
    char *test_lt="(< 10 2 )";
    
    //    char test_define_add[]="(define (add exp) (+ exp))";
    //    char test_call_define[]="(add 2)";
    //
    char *test_string[]={
        test_primop,
        test_lambda,
        test_lambda2,
        test_define,
        test_define2,
        test_define3,
        test_if,
        test_car,
        test_cdr,
        test_cons,
        test_cons2,
        test_define_set,
        test_setb,
        test_setcar,
        test_begin,
        test_mix,
        test_mix1,
        test_mix2,
        test_gt,
        test_lt
    };
    char *test_result[]={
        "56.66666667",//test_primop
        "10",//test_lambda
        "1128",//test_lambda2
        "",//test_define
        "", //test_define2
        "",//test_define3
        "2",//(if (= 12 13) 1 2)
        "a",//(car '(a b c d))
        "(b . (c . (d . nil)))",//test_cdr
        "((a . nil) . c)",//test_cons
        "c",//test_cons2
        "",//test_define_set
        "",//test_setb
        "(b . (c . (d . (e . (f . nil)))))",//test_setcar
        "17",//test_begin
        "",//test_mix
        "",//test_mix1
        "13",//test_mix2
        "#t",//test_gt
        "#f",//test_lt
    };
    for(int i=0;i<sizeof(test_string)/sizeof(char*);i++){
        test_eval(i,test_string[i],test_result[i],type);
    }
    return 0;
}
Пример #18
0
void test_eval_expect(duk_context* ctx, const char* code, const char* expected) {
	test_eval(ctx, code);
	const char* result = duk_require_string(ctx, -1);
	test_assert(strcmp(result, expected) == 0);
	duk_pop(ctx);
}