static void
test_tmplayer_do_test (SubParseInputChunk * input, guint num)
{
  do_test (input, num, "utf8");
}
Beispiel #2
0
int main() {
   start_regex_engine();
   do_test();
   cleanup_regex_engine();
   return 0;
}
Beispiel #3
0
int main(int argc, char** argv)
{
    (void)argc;
    (void)argv;

#if 1
    const char* testFiles[] = {
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/01 Seven Songs for Seventh Saga - I. Wind.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/02 Seven Songs for Seventh Saga - II. Water.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/03 Seven Songs for Seventh Saga - III. Star.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/04 Seven Songs for Seventh Saga - IV. Sky.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/05 Seven Songs for Seventh Saga - V. Moon.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/06 Seven Songs for Seventh Saga - VI. Light.flac",
        "ocremix_tests/7th Saga - Seven Songs for Seventh Saga/FLAC/07 Seven Songs for Seventh Saga - VII. Wizard.flac",

        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/01 John Ryan - This Is the Moment [Main Theme of Apex 2015].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/02 DusK - A Day Like No Other [Ultimate Marvel vs. Capcom 3].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/03 DarkeSword - Got My Mind on My Money Match [Super Smash Bros. for Wii U].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/04 CJthemusicdude - Smashed Fridge Bits [Super Smash Bros. Melee].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/05 Amphibious - Forest Fire [Pokemon X and Y].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/06 DjjD - Bull in a China Shop [Super Smash Bros. Melee].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/07 Sixto Sounds - Falcon DREAM!! [Super Smash Bros. Brawl].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/08 WillRock - Filler Instinct [Killer Instinct].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/09 Neblix - Girl from Another World [Ultra Street Fighter IV].flac",
        "ocremix_tests/Apex 2015 - This Is the Moment/FLAC/10 Ivan Hakstok - May the Stars Light Your Way [Guilty Gear Xrd].flac",

        "ocremix_tests/CEO 2015 - Champion/FLAC/01 O_Super x Mag.Lo - CEO Champion [Main Theme of CEO 2015].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/02 Jeff Matthews - The Last Kill [Killer Instinct].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/03 DarkeSword - Kuro Yuki [Persona 4 Arena].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/04 DjjD - Prodigious Blitz [Tekken Tag Tournament 2].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/05 Richie Branson - Iron Fist [Tekken Theme of CEO 2015].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/06 Flexstyle - It's Okay, I Still Made Money [Divekick].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/07 zykO - #unanimous #undisputed [Super Smash Bros. for Wii U].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/08 Benjamin Briggs - FALCON PUNCH [Super Smash Bros. Theme of CEO 2015].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/09 Neblix - Together, We Fly [Super Smash Bros. Melee].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/10 DarkeSword - Fatalistic [Mortal Kombat].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/11 Richie Branson - Finish Him [Mortal Kombat Theme of CEO 2015].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/12 DarkeSword - U JELLY! [Guilty Gear X].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/13 Nutritious - Dash Cancel [Ultra Street Fighter IV].flac",
        "ocremix_tests/CEO 2015 - Champion/FLAC/14 Ivan Hakstok, Sixto Sounds - What's Your Poison [Ultimate Marvel vs. Capcom 3].flac",

        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-01 Preluematsude (Prelude) [Jeff Ball].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-02 The Last March (The Imperial Army) [Dr. Manhattan].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-03 Rebirth (Revival) [Brandon Strader].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-04 Rebel Dream [Main Theme (FF1), The Rebel Army, Find Your Way (FF8), Main Theme] (BONKERS).flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-05 Leon Is a F*****g Dick (Battle Theme 1) [Kidd Cabbage].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-06 garLACTUS Win [Victory, Fanfare (FF7)] (Darkmoocher).flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-07 Deuces (Ancient Castle) [mellogear].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-08 Firion N Maria (Will Take You to the Rebels) [The Rebel Army] (PrototypeRaptor).flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-09 Analog Freedom (Town, The Rebel Army) [BONKERS].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-10 the final WON (Battle Theme A, Victory) [W!SE the all.E].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/1-11 Rebellion (Dead Music, The Rebel Army) [Brandon Strader, Chernabogue, Detective Tuesday].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-01 Heroes of Dawn [Chaos Temple (FF1), Reunion, The Rebel Army, Deep Under the Water (FF3), Dead Music (FF1)] (PacificPoem).flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-02 Snakeyes (Battle Theme B) [zykO].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-03 Grind My Crank (Tower of the Magi) [XPRTNovice].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-04 Personification of Evil (The Emperor's Rebirth, Escape!) [Tuberz McGee].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-05 A Kingdom Fallen (Main Theme) [Sixto Sounds].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-06 Torchlit (Dungeon) [Viking Guitar].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-07 GG but ___ Solos Win [Victory, The Winner (FF8)] (Sir Jordanius feat. Brandon Strader).flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-08 Castellum Infernum (Castle Pandemonium) [Brandon Strader].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-09 Imperial Rapture (Battle Theme 2) [IanFitC].flac",
        "ocremix_tests/Final Fantasy II - Rebellion/FLAC/2-10 Finally (Finale) [Hat].flac",

        "ocremix_tests/01 The Orichalcon - megAsfear (Title).flac",
        "ocremix_tests/02 Evil Horde - Running from Evil Horde (MAP01 - Running from Evil).flac",
        "ocremix_tests/03 analoq - Adrian's Sleep (MAP25 - Adrian's Asleep).flac",
        "ocremix_tests/04 Mazedude - Westside Archvile (MAP20 - Message for the Archvile).flac",
        "ocremix_tests/05 Jovette Rivera - The Countdown (MAP03 - Countdown to Death).flac",
        "ocremix_tests/06 The Orichalcon - Crushing Headache (MAP06 - In the Dark).flac",
        "ocremix_tests/07 Mazedude - Silent Healer (MAP02 - The Healer Stalks).flac",
        "ocremix_tests/08 Big Giant Circles, Flik - Icon of Sinwave (MAP30 - Opening to Hell).flac",
        "ocremix_tests/09 John Revoredo - 31 Seconds (MAP09 - Into Sandy's City).flac",
        "ocremix_tests/10 Mazedude, Ailsean - The End of Hell (Endgame).flac",
        "ocremix_tests/11 phoenixdk - No Smoking Area (MAP23 - Bye Bye American Pie).flac",
        "ocremix_tests/12 Evil Horde - The Duel (MAP08 - The Dave D. Taylor Blues).flac",
        "ocremix_tests/13 djpretzel - Red Waltz (Intermission).flac",
        "ocremix_tests/Bonus phoenixdk - Ablaze (MAP10 - The Demon's Dead).flac",

        "Hallelujah.flac",
        "1 Sullivan The Lost Chord, Seated one day at the organ.FLAC",
        "1 Vaet Videns Dominus.FLAC",
        "3 Schubert String Quartet No 14 in D minor Death and the Maiden, D810 - Movement 3 Scherzo Allegro molto.FLAC",
        "14 Clementi Piano Sonata in D major, Op 25 No 6 - Movement 2 Un poco andante.FLAC",
        "E+questa+vita+un+lampo+Studio+Master.flac",
        "recit24bit.flac",
        "recit16bit.flac",
        "recit8bit.flac",
        "song1.flac",
        "BIS1536-001-flac_24.flac",
        "BIS1447-002-flac_24.flac",
    };

    unsigned int testCount = sizeof(testFiles) / sizeof(testFiles[0]);
    for (unsigned int i = 0; i < testCount; ++i)
    {
        const char* filename = testFiles[i];

        if (do_test(filename)) {
            printf("TEST PASSED: %s\n", filename);
        }
    }
#endif


#if 0
    FILE* pFile;
    //if (fopen_s(&pFile, "BIS1536-001-flac_24.flac", "rb") != 0) {
    //if (fopen_s(&pFile, "BIS1447-002-flac_24.flac", "rb") != 0) {
    //if (fopen_s(&pFile, "song1.flac", "rb") != 0) {
    //if (fopen_s(&pFile, "recit24bit.flac", "rb") != 0) {
    if (fopen_s(&pFile, "recit8bit.flac", "rb") != 0) {
        return -1;
    }

    fseek(pFile, 0, SEEK_END);
    size_t fileDataSize = (size_t)ftell(pFile);
    fseek(pFile, 0, SEEK_SET);

    void* pFileData = malloc(fileDataSize);
    fread(pFileData, 1, fileDataSize, pFile);
    fclose(pFile);

    drflac* pFlac = drflac_open_memory(pFileData, fileDataSize);
    if (pFlac == NULL) {
        return -1;
    }

    uint64_t firstSample = pFlac->totalSampleCount / 2;
    drflac_seek_to_sample(pFlac, firstSample);

    int* pSampleData = malloc((size_t)pFlac->totalSampleCount * sizeof(int));
    drflac_read_s32(pFlac, (size_t)(pFlac->totalSampleCount - firstSample), pSampleData);


    //drflac_seek_to_sample(&flac, 0);
    //drflac_read_s32(&flac, (size_t)(flac.totalSampleCount - firstSample), pSampleData);


    draudio_context* pContext = draudio_create_context();
    if (pContext == NULL) {
        return -2;
    }

    draudio_device* pDevice = draudio_create_output_device(pContext, 0);
    if (pDevice == NULL) {
        return -3;
    }

    draudio_buffer_desc bufferDesc;
    memset(&bufferDesc, 0, sizeof(&bufferDesc));
    bufferDesc.format        = draudio_format_pcm;
    bufferDesc.channels      = pFlac->channels;
    bufferDesc.sampleRate    = pFlac->sampleRate;
    bufferDesc.bitsPerSample = sizeof(int)*8;
    bufferDesc.sizeInBytes   = (size_t)pFlac->totalSampleCount * sizeof(int);
    bufferDesc.pData         = pSampleData;

    draudio_buffer* pBuffer = draudio_create_buffer(pDevice, &bufferDesc, 0);
    if (pBuffer == NULL) {
        return -4;
    }


    draudio_play(pBuffer, false);
#endif


#if 0
    drflac flac;
    drflac_open_file(&flac, "MyFile.flac");

    int* pSampleData = malloc((size_t)flac.totalSampleCount * sizeof(int));
    drflac_read_s32(&flac, flac.totalSampleCount, pSampleData);
#endif

    //_getch();
    return 0;
}
Beispiel #4
0
void fptest1( CYG_ADDRWORD id )
{
    while(1)
        do_test( fpt1_values, FP1_COUNT, 2000000000, id, "fptest1" );
}
Beispiel #5
0
void fptest3( CYG_ADDRWORD id )
{
    while(1)
        do_test( fpt3_values, FP3_COUNT, 2000000000, id, "fptest3" );
}
Beispiel #6
0
static int __test__bpf(int idx)
{
	int ret;
	void *obj_buf;
	size_t obj_buf_sz;
	struct bpf_object *obj;

	ret = test_llvm__fetch_bpf_obj(&obj_buf, &obj_buf_sz,
				       bpf_testcase_table[idx].prog_id,
				       true, NULL);
	if (ret != TEST_OK || !obj_buf || !obj_buf_sz) {
		pr_debug("Unable to get BPF object, %s\n",
			 bpf_testcase_table[idx].msg_compile_fail);
		if (idx == 0)
			return TEST_SKIP;
		else
			return TEST_FAIL;
	}

	obj = prepare_bpf(obj_buf, obj_buf_sz,
			  bpf_testcase_table[idx].name);
	if ((!!bpf_testcase_table[idx].target_func) != (!!obj)) {
		if (!obj)
			pr_debug("Fail to load BPF object: %s\n",
				 bpf_testcase_table[idx].msg_load_fail);
		else
			pr_debug("Success unexpectedly: %s\n",
				 bpf_testcase_table[idx].msg_load_fail);
		ret = TEST_FAIL;
		goto out;
	}

	if (obj) {
		ret = do_test(obj,
			      bpf_testcase_table[idx].target_func,
			      bpf_testcase_table[idx].expect_result);
		if (ret != TEST_OK)
			goto out;
		if (bpf_testcase_table[idx].pin) {
			int err;

			if (!bpf_fs__mount()) {
				pr_debug("BPF filesystem not mounted\n");
				ret = TEST_FAIL;
				goto out;
			}
			err = mkdir(PERF_TEST_BPF_PATH, 0777);
			if (err && errno != EEXIST) {
				pr_debug("Failed to make perf_test dir: %s\n",
					 strerror(errno));
				ret = TEST_FAIL;
				goto out;
			}
			if (bpf_object__pin(obj, PERF_TEST_BPF_PATH))
				ret = TEST_FAIL;
			if (rm_rf(PERF_TEST_BPF_PATH))
				ret = TEST_FAIL;
		}
	}

out:
	bpf__clear();
	return ret;
}
Beispiel #7
0
/*ARGSUSED*/
int
main(int argc, char *argv[])
{
	char *brk_max_addr, *hole_addr, *brk_start, *hole_start;
	size_t pagesize = (size_t)sysconf(_SC_PAGE_SIZE);
	time_t	t;

	progname = argv[0];

	(void)time(&t);
//	(void)printf("%s: Started %s", argv[0], ctime(&t));
	if ((brk_start = sbrk(0)) == NEG1) {
		ERROR("initial sbrk failed");
		anyfail();
	}
	if ((u_long)brk_start % (u_long)pagesize) {
		if (sbrk(pagesize - ((u_long)brk_start % (u_long)pagesize))
			== NEG1)
		{
			ERROR("couldn't round up brk to a page boundary");
        	        anyfail();
		}
	}
	/* The brk is now at the beginning of a page. */

	if ((hole_addr = hole_start = sbrk(NUM_SEGS * 2 * pagesize)) == NEG1) {
		ERROR("couldn't brk large space for segments");
                anyfail();
	}
	if ((brk_max_addr = sbrk(0)) == NEG1) {
		ERROR("couldn't find top of brk");
                anyfail();
	}
	do_test((caddr_t)brk_max_addr, pagesize);

	/* now make holes and repeat test */
	while (hole_addr + pagesize < brk_max_addr) {
		if (munmap(hole_addr, pagesize) == -1) {
			ERROR("failed to munmap odd hole in brk segment");
	                anyfail();
		}
		hole_addr += 2 * pagesize;
	}

	if (brk_max_addr != sbrk(0)) {
		ERROR("do_test should leave the top of brk where it began");
                anyfail();
	}
	do_test((caddr_t)brk_max_addr, pagesize);

	/* Shrink brk */
	if (sbrk(-NUM_SEGS * pagesize) == NEG1) {
		ERROR("couldn't brk back over holes");
                anyfail();
	}
	if ((brk_max_addr = sbrk(0)) == NEG1) {
		ERROR("couldn't find top of break again");
                anyfail();
	}
	/* sbrked over about half the holes */

	hole_addr = hole_start + pagesize; /* munmap the other pages */
	while (hole_addr + pagesize < brk_max_addr) {
		if (munmap(hole_addr, pagesize) == -1) {
			ERROR("failed to munmap even hole in brk segment");
        	        anyfail();
		}
		hole_addr += 2 * pagesize;
	}
	/* munmaped the rest of the brk except a little at the beginning */

	if (brk(brk_start) == -1) {
		ERROR("failed to completely remove brk");
                anyfail();
	}
	if (sbrk(pagesize) == NEG1 || sbrk(-pagesize) == NEG1) {
		ERROR("failed to fiddle with brk at the end");
                anyfail();
	}
	/* Ask for a ridiculously large mmap region at a high address */
	if (mmap((caddr_t)(1UL << (POINTER_SIZE  - 1)) - pagesize,
		(size_t)((1UL << (POINTER_SIZE - 1)) - pagesize),
		PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_FIXED|MAP_SHARED, 0, 0)
		!= (caddr_t)-1)
	{
		ERROR("really large mmap didn't fail");
                anyfail();
	}
	if (errno != ENOMEM && errno != EINVAL) {
		ERROR("really large mmap didn't set errno = ENOMEM nor EINVAL");
                anyfail();
	}
	(void)time(&t);
//	(void)printf("%s: Finished %s", argv[0], ctime(&t));
	ok_exit();
	tst_exit();
}
Beispiel #8
0
static void
check_add_subtract_overflow (void)
{
    int i;

    for (i = 0; i < NREPS; i++)
    {
	/* Div to avoid addition overflows; we're looking for lcd conversion overflows here. */

	int exp_a = rand () % 1000;
	int exp_b = rand () % 1000;
        gint64 bin_deno_a = (exp_a == 0 ? 1 : exp_a);
	gint64 bin_deno_b = (exp_b == 0 ? 1 : exp_b);
/*
	int exp_a = rand () % 11;
	int exp_b = rand () % 11;
	gint64 bin_deno_a = (1 << exp_a);
	gint64 bin_deno_b = (1 << exp_a);
*/
	gint64 dec_deno_a = powten (exp_a % 7);
	gint64 dec_deno_b = powten (exp_b % 7);
        gint64 na = get_random_gint64 () % (1000000 * dec_deno_a);
        gint64 nb = get_random_gint64 () % (1000000 * dec_deno_b);
	gnc_numeric result;
	GNCNumericErrorCode err;
	gchar *errmsg;

        gnc_numeric ba = gnc_numeric_create(na, bin_deno_a);
        gnc_numeric bb = gnc_numeric_create(nb, bin_deno_b);
        gnc_numeric da = gnc_numeric_create(na, dec_deno_a);
        gnc_numeric db = gnc_numeric_create(nb, dec_deno_b);
	gchar *ba_str = gnc_numeric_to_string (ba);
	gchar *bb_str = gnc_numeric_to_string (bb);
	gchar *da_str = gnc_numeric_to_string (da);
	gchar *db_str = gnc_numeric_to_string (db);


        /* Add */

	result = gnc_numeric_add(ba, bb, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", ba_str, bb_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);

	result = gnc_numeric_add(da, bb, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", da_str, bb_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);
	result = gnc_numeric_add(ba, db, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", ba_str, db_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);

	result = gnc_numeric_add(da, db, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", da_str, db_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);
        /* Subtract */

	result = gnc_numeric_sub(ba, bb, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", ba_str, bb_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);

	result = gnc_numeric_sub(da, bb, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", da_str, bb_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);
	result = gnc_numeric_sub(ba, db, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", ba_str, db_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);

	result = gnc_numeric_sub(da, db, GNC_DENOM_AUTO, GNC_HOW_DENOM_EXACT);
	err = gnc_numeric_check (result);
	errmsg = g_strdup_printf ("%s + %s raised %s", da_str, db_str,
				  gnc_numeric_errorCode_to_string (err));
	do_test (err == 0, errmsg);
	g_free (errmsg);

	g_free (ba_str);
	g_free (bb_str);
	g_free (da_str);
	g_free (db_str);
    }

}
Beispiel #9
0
TestWindow* TestWindow::TestFunc(const char* param, int val)
{
	if( this ) do_test(param,val);
	return this;
}
Beispiel #10
0
int
Ndb_cluster_connection_impl::init_nodes_vector(Uint32 nodeid,
					       const ndb_mgm_configuration 
					       &config)
{
  DBUG_ENTER("Ndb_cluster_connection_impl::init_nodes_vector");
  ndb_mgm_configuration_iterator iter(config, CFG_SECTION_CONNECTION);
  
  for(iter.first(); iter.valid(); iter.next())
  {
    Uint32 nodeid1, nodeid2, remoteNodeId, group= 5;
    const char * remoteHostName= 0, * localHostName= 0;
    if(iter.get(CFG_CONNECTION_NODE_1, &nodeid1)) continue;
    if(iter.get(CFG_CONNECTION_NODE_2, &nodeid2)) continue;

    if(nodeid1 != nodeid && nodeid2 != nodeid) continue;
    remoteNodeId = (nodeid == nodeid1 ? nodeid2 : nodeid1);

    iter.get(CFG_CONNECTION_GROUP, &group);

    {
      const char * host1= 0, * host2= 0;
      iter.get(CFG_CONNECTION_HOSTNAME_1, &host1);
      iter.get(CFG_CONNECTION_HOSTNAME_2, &host2);
      localHostName  = (nodeid == nodeid1 ? host1 : host2);
      remoteHostName = (nodeid == nodeid1 ? host2 : host1);
    }

    Uint32 type = ~0;
    if(iter.get(CFG_TYPE_OF_SECTION, &type)) continue;

    switch(type){
    case CONNECTION_TYPE_SHM:{
      break;
    }
    case CONNECTION_TYPE_SCI:{
      break;
    }
    case CONNECTION_TYPE_TCP:{
      // connecting through localhost
      // check if config_hostname is local
      if (SocketServer::tryBind(0,remoteHostName))
	group--; // upgrade group value
      break;
    }
    }
    if (m_all_nodes.push_back(Node(group,remoteNodeId)))
    {
      DBUG_RETURN(-1);
    }
    DBUG_PRINT("info",("saved %d %d", group,remoteNodeId));
    for (int i= m_all_nodes.size()-2;
	 i >= 0 && m_all_nodes[i].group > m_all_nodes[i+1].group;
	 i--)
    {
      Node tmp= m_all_nodes[i];
      m_all_nodes[i]= m_all_nodes[i+1];
      m_all_nodes[i+1]= tmp;
    }
  }

  int i;
  Uint32 cur_group, i_group= 0;
  cur_group= ~0;
  for (i= (int)m_all_nodes.size()-1; i >= 0; i--)
  {
    if (m_all_nodes[i].group != cur_group)
    {
      cur_group= m_all_nodes[i].group;
      i_group= i+1;
    }
    m_all_nodes[i].next_group= i_group;
  }
  cur_group= ~0;
  for (i= 0; i < (int)m_all_nodes.size(); i++)
  {
    if (m_all_nodes[i].group != cur_group)
    {
      cur_group= m_all_nodes[i].group;
      i_group= i;
    }
    m_all_nodes[i].this_group= i_group;
  }
#if 0
  for (i= 0; i < (int)m_all_nodes.size(); i++)
  {
    fprintf(stderr, "[%d] %d %d %d %d\n",
	   i,
	   m_all_nodes[i].id,
	   m_all_nodes[i].group,
	   m_all_nodes[i].this_group,
	   m_all_nodes[i].next_group);
  }

  do_test();
#endif
  DBUG_RETURN(0);
}
Beispiel #11
0
static void
check_equality_operator (void)
{
    int i, m;
    gint mult;
    gint64 f, deno, numer;
    gnc_numeric big, rbig;
    gnc_numeric val, mval;
    gnc_numeric bval, rval;
    /* Check equality operator for some large numer/denom values */
    numer = 1 << 30;
    numer <<= 30;   /* we don't trust cpp to compute 1<<60 correctly */
    deno = 1 << 30;
    deno <<= 20;
    rbig = gnc_numeric_create (numer, deno);

    big = gnc_numeric_create (1 << 10, 1);
    do_test (gnc_numeric_equal(big, rbig), "equal to billion");

    big = gnc_numeric_create (1 << 20, 1 << 10);
    do_test (gnc_numeric_equal(big, rbig), "equal to 1<<20/1<<10");

    big = gnc_numeric_create (1 << 30, 1 << 20);
    do_test (gnc_numeric_equal(big, rbig), "equal to 1<<30/1<<20");

    numer = 1 << 30;
    numer <<= 30;   /* we don't trust cpp to compute 1<<60 correctly */
    deno = 1 << 30;
    rbig = gnc_numeric_create (numer, deno);

    big = gnc_numeric_create (1 << 30, 1);
    do_test (gnc_numeric_equal(big, rbig), "equal to 1<<30");

    numer = 1 << 30;
    numer <<= 10;
    big = gnc_numeric_create (numer, 1 << 10);
    do_test (gnc_numeric_equal(big, rbig), "equal to 1<<40/1<<10");

    numer <<= 10;
    big = gnc_numeric_create (numer, 1 << 20);
    do_test (gnc_numeric_equal(big, rbig), "equal to 1<<50/1<<20");

    /* We assume RAND_MAX is less that 1<<32 */
    for (i = 0; i < NREPS; i++)
    {
        deno = rand() / 2;
        mult = rand() / 2;
        numer = rand() / 2;

        /* avoid 0 */
        if (deno == 0 || mult == 0)
        {
            i--;
            continue;
        }

        val = gnc_numeric_create (numer, deno);
        mval = gnc_numeric_create (numer * mult, deno * mult);

        /* The reduced version should be equivalent */
        bval = gnc_numeric_reduce (val);
        rval = gnc_numeric_reduce (mval);
        check_unary_op (gnc_numeric_eq,
                        bval, rval, mval, "expected %s got %s = reduce(%s)");

        /* The unreduced versions should be equal */
        check_unary_op (gnc_numeric_equal,
                        val, mval, mval, "expected %s = %s");

        /* Certain modulo's should be very cleary un-equal; this
         * helps stop funky modulo-64 aliasing in compares that
         * might creep in. */
        mval.denom >>= 1;
        mval.num >>= 1;
        m = 0;
        f = mval.denom;
        while (f % 2 == 0)
        {
            f >>= 1;
            m++;
        }
        if (1 < m)
        {
            gint64 nn = 1 << (32 - m);
            nn <<= 32;
            nn += mval.num;
            val = gnc_numeric_create (2 * nn, 2 * mval.denom);
            check_unary_op (gnc_numeric_unequal,
                            val, mval, mval, "expected unequality %s != %s");

        }
    }
}
Beispiel #12
0
static void
test_employee (void)
{
    QofBackend *be;
    QofBook *book;
    QofSession *session;
    GncEmployee *employee;

    session = qof_session_new();
    qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
    book = qof_session_get_book(session);
    /* The book *must* have a backend to pass the test of the 'dirty' flag */
    /* See the README file for details */

    be = qof_book_get_backend (book);

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_new (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
#if 0
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
#endif
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (safe_strcmp (str, res) == 0, "Printable equals");
    }
}
Beispiel #13
0
static void
create_data (QofSession *original, guint counter)
{
    QofCollection *coll;
    QofBook *start;
    mygrand *grand1;
    myparent *parent1;
    mychild *child1;

    start = qof_session_get_book(original);
    grand1 = (mygrand*)qof_object_new_instance(GRAND_MODULE_NAME, start);
    do_test ((NULL != &grand1->inst), "instance init");
    switch (counter)
    {
    case 0 :   /* NULL tree */
    {
        do_test((grand1 != NULL), "empty tree check");
        coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Too many grandparents found - should be 1");
        coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
        do_test((qof_collection_count(coll) == 0),
                "child found, should be empty");
        coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
        do_test((qof_collection_count(coll) == 0),
                "tree not empty: parent found");
        break;
    }
    case 1 :   /* one parent, no child */
    {
        parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
        grand_setChild(grand1, parent1);
        do_test((parent1 != NULL), "single parent check");
        do_test((grand_getChild(grand1) == parent1), "set child in grandparent");
        coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of grandparents, should be 1");
        coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
        do_test((qof_collection_count(coll) == 0),
                "Should be no child entities this iteration.");
        coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of parents found, should be 1");
        break;
    }
    case 2 :   /* one parent, one child */
    {
        parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
        grand_setChild(grand1, parent1);
        child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
        parent1 = grand_getChild(grand1);
        parent_setChild(parent1, child1);
        do_test((child1 != NULL), "one parent with one related child");
        do_test((child1 == parent_getChild(parent1)), "child of single parent");
        coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of grandparents. Should be 1");
        coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of child entities, should be 1");
        coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of parents. Should be 1");
        break;
    }
    case 3 :   /* same grand, new parent, same child */
    {
        child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
        parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
        grand_setChild(grand1, parent1);
        parent_setChild(parent1, child1);
        do_test((parent1 == grand_getChild(grand1)), "same grandparent, new parent");
        do_test((child1 == parent_getChild(parent1)), "new parent, same child");
        coll = qof_book_get_collection(start, GRAND_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of grandparents. Should be 1, Iteration 3.");
        coll = qof_book_get_collection(start, CHILD_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of child entities, should be 1. Iteration 3.");
        coll = qof_book_get_collection(start, PARENT_MODULE_NAME);
        do_test((qof_collection_count(coll) == 1),
                "Wrong number of parents. Should be 1. Iteration 3.");
        break;
    }
    case 4 :   /* new grand, unrelated parent, child unrelated to grand */
    {
        grand1 = (mygrand*)qof_object_new_instance(GRAND_MODULE_NAME, start);
        parent1 = (myparent*)qof_object_new_instance(PARENT_MODULE_NAME, start);
        child1 = (mychild*)qof_object_new_instance(CHILD_MODULE_NAME, start);
        parent_setChild(parent1, child1);
        do_test((NULL == grand_getChild(grand1)), "new grand, unrelated parent");
        do_test((child1 == parent_getChild(parent1)), "child unrelated to grand");
        coll = grand_getDescend(grand1);
        do_test((coll != NULL), "grandparent not valid");
        if (coll)
        {
            QofInstance *ent;

            ent = QOF_INSTANCE(child1);
            qof_collection_add_entity(coll, ent);
            grand_setDescend(grand1, coll);
            qof_collection_destroy(coll);
            do_test((g_list_length(grand1->descend) > 0), "entity not added");
            do_test((qof_collection_count(grand_getDescend(grand1)) > 0),
                    "empty collection returned");
        }
        break;
    }
    }
}
static void
test_microdvd_do_test (SubParseInputChunk * input, guint num)
{
  do_test (input, num, "pango-markup");
}
Beispiel #15
0
void test_mpsl2(void)
{
    mpdm_t v;
    mpdm_t w;

    /* execution tests */
    v = do_test_mpsl("666;");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    do_test("literal number", mpdm_ival(v) == 666);

    v = do_test_mpsl("\"goodbye\";");
    v = do_test_exec(v, NULL);
    do_test("literal string", mpdm_cmp(v, MPDM_S(L"goodbye")) == 0);

    v = do_test_mpsl("1 + 3 + 5;");
    v = do_test_exec(v, NULL);
    do_test("mpsl calculator 1", mpdm_rval(v) == 9.0);

    v = do_test_mpsl("1 + ((3 - 5) * 8);");
    v = do_test_exec(v, NULL);
    do_test("mpsl calculator 2", mpdm_rval(v) == -15.0);

    /* next value cannot be tested as an exact equality,
       as rounding errors will manifest */
    v = do_test_mpsl("1.5 + ((3.1 - 5.8) * 8.0);");
    v = do_test_exec(v, NULL);
    do_test("mpsl calculator 3", mpdm_rval(v) < -20.0 && mpdm_rval(v) > -21.0);

    v = do_test_mpsl("2 + 3 * 4;");
    v = do_test_exec(v, NULL);
    do_test("mpsl calculator 4", mpdm_rval(v) == 14.0);

    v = do_test_mpsl("2 * 3 + 4;");
    v = do_test_exec(v, NULL);
    do_test("mpsl calculator 5", mpdm_rval(v) == 10.0);

    v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL);
    mpdm_ref(v);
    w = do_test_exec(do_test_mpsl("2 + (3 * 4);"), NULL);
    do_test("mpsl calculator 6 (operator precedence)", mpdm_rval(v) == mpdm_rval(w));
    mpdm_unref(v);

    v = do_test_exec(do_test_mpsl("2 + 3 * 4;"), NULL);
    mpdm_ref(v);
    w = do_test_exec(do_test_mpsl("(2 + 3) * 4;"), NULL);
    do_test("mpsl calculator 7 (operator precedence)", mpdm_rval(v) != mpdm_rval(w));
    mpdm_unref(v);

    v = do_test_mpsl("/* array */ [\"this\", \"one\", \"is\", 666, \"cool\"];");
    v = do_test_exec(v, NULL);
    mpdm_dump(v);
    do_test("mpsl array", mpdm_ival(mpdm_get_i(v, 3)) == 666);

    v = do_test_mpsl
        ("/* hash */ { \"enero\" => \"january\", \"febrero\" => \"february\" };");
    v = do_test_exec(v, NULL);
    mpdm_dump(v);
    do_test("mpsl hash", mpdm_cmp(mpdm_get(v,
                        MPDM_S(L"febrero")),
                      MPDM_S(L"february")) == 0);

    v = do_test_mpsl("! 1;");
    v = do_test_exec(v, NULL);
    do_test("boolean not 1", !mpdm_is_true(v));
    v = do_test_mpsl("! 0;");
    v = do_test_exec(v, NULL);
    do_test("boolean not 2", v != NULL);

    v = do_test_mpsl("1 && 3;");
    v = do_test_exec(v, NULL);
    do_test("boolean and 1", mpdm_ival(v) == 3);
    v = do_test_mpsl("1 && 0;");
    v = do_test_exec(v, NULL);
    do_test("boolean and 2", !mpdm_is_true(v));
    v = do_test_mpsl("0 && 1;");
    v = do_test_exec(v, NULL);
    do_test("boolean and 3", !mpdm_is_true(v));

    v = do_test_mpsl("1 || 3;");
    v = do_test_exec(v, NULL);
    do_test("boolean or 1", mpdm_ival(v) == 1);
    v = do_test_mpsl("2 || 0;");
    v = do_test_exec(v, NULL);
    do_test("boolean or 2", mpdm_ival(v) == 2);
    v = do_test_mpsl("0 || 3;");
    v = do_test_exec(v, NULL);
    do_test("boolean or 3", mpdm_ival(v) == 3);

    v = do_test_mpsl("6 == 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric == 1", v != NULL);
    v = do_test_mpsl("8.0 == 8.0;");
    v = do_test_exec(v, NULL);
    do_test("numeric == 2", v != NULL);
    v = do_test_mpsl("6 == 8;");
    v = do_test_exec(v, NULL);
    do_test("numeric == 3", !mpdm_is_true(v));

    v = do_test_mpsl("6 != 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric != 1", !mpdm_is_true(v));
    v = do_test_mpsl("8.0 != 8.0;");
    v = do_test_exec(v, NULL);
    do_test("numeric != 2", !mpdm_is_true(v));
    v = do_test_mpsl("6 != 8;");
    v = do_test_exec(v, NULL);
    do_test("numeric != 3", v != NULL);

    v = do_test_mpsl("6 < 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric < 1", !mpdm_is_true(v));
    v = do_test_mpsl("8 < 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric < 2", !mpdm_is_true(v));
    v = do_test_mpsl("5 < 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric < 3", v != NULL);

    v = do_test_mpsl("6 > 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric > 1", !mpdm_is_true(v));
    v = do_test_mpsl("8 > 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric > 2", v != NULL);
    v = do_test_mpsl("5 > 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric > 3", !mpdm_is_true(v));

    v = do_test_mpsl("6 <= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric <= 1", v != NULL);
    v = do_test_mpsl("8 <= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric <= 2", !mpdm_is_true(v));
    v = do_test_mpsl("5 <= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric <= 3", v != NULL);

    v = do_test_mpsl("6 >= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric >= 1", v != NULL);
    v = do_test_mpsl("8 >= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric >= 2", v != NULL);
    v = do_test_mpsl("5 >= 6;");
    v = do_test_exec(v, NULL);
    do_test("numeric >= 3", !mpdm_is_true(v));

    v = do_test_mpsl("11 % 6;");
    v = do_test_exec(v, NULL);
    do_test("modulo", mpdm_ival(v) == 5);

    v = do_test_mpsl("variable=16384;");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    do_test("assign 1", mpdm_ival(v) == 16384);

    v = do_test_mpsl("array=[10, 20, 30, 40];");
    v = do_test_exec(v, NULL);
    do_test("assign 2", mpdm_ival(mpdm_get_i(v, 2)) == 30);

    v = do_test_mpsl("a=1; b=2; c=3;");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);

    v = do_test_mpsl("CACHE={}; CACHE.regex=[]; CACHE.regex[0]=12345;");
    v = do_test_exec(v, NULL);

    v = do_test_mpsl("variable;");
    v = do_test_exec(v, NULL);
    do_test("symval 1", mpdm_ival(v) == 16384);

    v = do_test_mpsl("variable2=1 + ((3 - 5) * 8); variable2;");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    do_test("symval 2", mpdm_rval(v) == -15);

    v = do_test_mpsl("variable3=variable2 * 2;");
    v = do_test_exec(v, NULL);
    do_test("symval 3", mpdm_ival(v) == -30);

    v = do_test_mpsl("sub mysum(a, b) { a + b; }");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    do_test("sub 1", v != NULL);

    v = do_test_mpsl("sub pi() { 3.1416; }");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    do_test("sub 2", v != NULL);

    v = do_test_mpsl("var10=pi();");
    v = do_test_exec(v, NULL);
    do_test("exec 1", mpdm_rval(v) == 3.1416);

    v = do_test_mpsl("var11=pi() * 10000; var11;");
    v = do_test_exec(v, NULL);
    do_test("exec 2", mpdm_rval(v) == 31416);

    v = do_test_mpsl("mysum(100, 20);");
    v = do_test_exec(v, NULL);
    do_test("exec 3", mpdm_rval(v) == 120.0);

    v = do_test_mpsl("a = NULL;");
    v = do_test_exec(v, NULL);
    do_test("NULL 1", v == NULL);

    v = do_test_mpsl("a == NULL;");
    v = do_test_exec(v, NULL);
    do_test("NULL 2", mpdm_ival(v) == 1);

    v = do_test_mpsl("local a, b; a = 1; b = 2;");
    v = do_test_exec(v, NULL);

    v = do_test_mpsl("a == NULL;");
    v = do_test_exec(v, NULL);
    do_test("local 1", mpdm_ival(v) == 1);

    v = do_test_mpsl("66 * -1;");
    v = do_test_exec(v, NULL);
    do_test("uminus", mpdm_ival(v) == -66);

    v = do_test_mpsl("\"test\" eq \"test\";");
    v = do_test_exec(v, NULL);
    do_test("streq 1", mpdm_is_true(v));

    v = do_test_mpsl("\"test\" eq \"prueba\";");
    v = do_test_exec(v, NULL);
    do_test("streq 1", !mpdm_is_true(v));

    v = do_test_mpsl("a = 6; ++ a;");
    v = do_test_exec(v, NULL);
    do_test("pinc", mpdm_ival(v) == 7);

    v = do_test_mpsl("a++;");
    v = do_test_exec(v, NULL);
    do_test("sinc", mpdm_ival(v) == 7);

    v = do_test_mpsl("a += 10;");
    v = do_test_exec(v, NULL);
    do_test("iadd", mpdm_ival(v) == 18);

    v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a == b) c=1000; c;");
    v = do_test_exec(v, NULL);
    do_test("if 1", mpdm_ival(v) == 3);

    v = do_test_mpsl("local a, b, c; a=1; b=2; c=3; if(a <= b) c=1000; c;");
    v = do_test_exec(v, NULL);
    do_test("if 2", mpdm_ival(v) == 1000);

    v = do_test_mpsl("local a, b, c; a=1; b=2; if(a == b) c=1000; else c=2000; c;");
    v = do_test_exec(v, NULL);
    do_test("ifelse", mpdm_ival(v) == 2000);

    v = do_test_mpsl("local a; a = 0; while(a < 100) { a++; } a;");
    v = do_test_exec(v, NULL);
    do_test("ifelse", mpdm_ival(v) == 100);

    v = do_test_mpsl("a=mysum(100, 50); a;");
    v = do_test_exec(v, NULL);
    do_test("mysum 1", mpdm_ival(v) == 150);

    v = do_test_mpsl("a=mysum(2000, 500); a;");
    v = do_test_exec(v, NULL);
    do_test("mysum 2", mpdm_ival(v) == 2500);

    w = mpdm_ref(MPDM_A(2));
    mpdm_set_i(w, MPDM_I(100), 0);
    mpdm_set_i(w, MPDM_I(50), 1);

    /* asks for the value of the mysum symbol (the code) */
    v = do_test_mpsl("mysum;");
    /* executes, so mysum() itself is being returned */
    v = do_test_exec(v, NULL);
    mpdm_dump(v);
    do_test("mysum 3", mpdm_ival(do_test_exec(v, w)) == 150);

    mpdm_set_i(w, MPDM_I(75), 1);
    do_test("mysum 4", mpdm_ival(do_test_exec(v, w)) == 175);

    /* compiles (and executes) the definition of gcd() */
    v = do_test_mpsl
        ("/* greatest common divisor (Euclid's algorithm) */ sub gcd(m, n) { while (m > 0) { if(n > m) { local t = m; m = n; n = t; } m -= n; } n; }");
    do_test_exec(v, NULL);

    /* gets a pointer to gcd() */
    v = do_test_exec(do_test_mpsl("gcd;"), NULL);
    mpdm_dump(v);

    /* executes gcd(100, 50); */
    mpdm_set_i(w, MPDM_I(50), 1);
    do_test("gcd() 1", mpdm_ival(do_test_exec(v, w)) == 50);

    /* executes gcd(100, 75); */
    mpdm_set_i(w, MPDM_I(75), 1);
    do_test("gcd() 2", mpdm_ival(do_test_exec(v, w)) == 25);

    mpdm_unref(w);

    /* string concatenation */
    w = mpdm_ref(MPDM_S(L"big lebowski"));

    v = do_test_mpsl("\"big\" ~ \" lebowski\";");
    do_test("~ (strcat 1)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);

    v = do_test_mpsl("\"big\" ~ \" \" ~ \"lebowski\";");
    do_test("~ (strcat 2)", mpdm_cmp(do_test_exec(v, NULL), w) == 0);

    mpdm_unref(w);
}
Beispiel #16
0
int main(int argc, char *argv[])
{
    int n;

    if (argc > 1 && strcmp(argv[1], "-v") == 0)
        verbose = 1;

    /* loop all tests */
    for (n = 0; rx_tests[n].rx != NULL; n++) {
        struct rx_test *r = &rx_tests[n];

        _do_test(r->rx, r->rx, r->tx, r->r, r->src_line);
    }

    /* + */
    do_test(L"+ 0 (really *)", L"one *world",   L"oneworld is enough", L"oneworld");
    do_test(L"+ 1", L"one +world",              L"oneworld", L"");
    do_test(L"+ 2", L"one +world",              L"one world", L"one world");
    do_test(L"+ 3", L"one +world",              L"one    world", L"one    world");
    do_test(L"+ 4", L"one +world",              L"oneworld is enough", L"");
    do_test(L"+ 5", L"one +world",              L"one world is enough", L"one world");
    do_test(L"+ 6", L"one +world",              L"one    world is enough", L"one    world");
    do_test(L"+ 7", L"one +world",              L"I say oneworld is enough", L"");
    do_test(L"+ 8", L"one +world",              L"I say one world is enough", L"one world");
    do_test(L"+ 9", L"one +world",              L"I say one    world is enough", L"one    world");

    /* escaped chars */
    do_test(L"esc 0 (really ?)", L"ready?",         L"ready!", L"ready");
    do_test(L"esc 1",            L"ready\\?",       L"ready!", L"");
    do_test(L"esc 2",            L"ready\\?",       L"ready?", L"ready?");
    do_test(L"esc 3",            L"triptico.com",   L"tripticoxcom", L"tripticoxcom");
    do_test(L"esc 4",            L"triptico\\.com", L"tripticoxcom", L"");
    do_test(L"esc 5",            L"triptico\\.com", L"triptico.com", L"triptico.com");
    do_test(L"esc 6",            L"\n",             L"string without newlines", L"");
    do_test(L"esc 7",            L"\n",             L"I'm\nbroken", L"\n");

    /* square bracket sets */
    do_test(L"[] 0", L"[^a-c]",     L"z", L"z");
    do_test(L"[] 1", L"[^a-cdzx]",  L"z", L"");
    do_test(L"[] 2", L"[a-c]",      L"z", L"");
    do_test(L"[] 3", L"[a-cdzx]",   L"z", L"z");
    do_test(L"[] 4", L"[a-c]",      L"b", L"b");
    do_test(L"[] 5", L"[abc]",      L"b", L"b");
    do_test(L"[] 6", L"[abc]",      L"d", L"");

    do_test(L"[] and * 0", L"[a-z][a-z]*",  L"1234 string 456", L"string");
    do_test(L"[] and * 1", L"[a-z][a-z]*:", L"1234 string key: value 456", L"key:");
    do_test(L"[] and * 2", L"[a-c]*de",     L"abcde", L"abcde");

    do_test(L"[] and + 0", L"[a-z]+",       L"1234 string 456", L"string");
    do_test(L"[] and + 1", L"[a-z]+:",      L"1234 string key: value 456", L"key:");

    /* alternate strings */
    do_test(L"Alt strings 0", L"(abc|def)1", L"try abf1 now", L"");
    do_test(L"Alt strings 1", L"(abc|def)1", L"try def1 now", L"def1");
    do_test(L"Alt strings 2", L"(abc|def)1", L"try abc1 now", L"abc1");

    /* substrings */
    do_test(L"Substrs and * 0", L"Rem(ark)* comment", L"Rem comment", L"Rem comment");
    do_test(L"Substrs and * 1", L"Rem(ark)* comment", L"Remarkark comment", L"Remarkark comment");
    do_test(L"Substrs and * 2", L"Rem(ark)* comment", L"Remark comment", L"Remark comment");
    do_test(L"Substrs and * 3", L"Rem(ark)* comment", L"<!-- Rem comment -->", L"Rem comment");
    do_test(L"Substrs and ? 0", L"Rem(ark)? comment", L"Rem comment", L"Rem comment");
    do_test(L"Substrs and ? 1", L"Rem(ark)? comment", L"Remark comment", L"Remark comment");

    do_test(L"More sets 0", L"'[^']*'", L"I have here a 'string' between quotes", L"'string'");
    do_test(L"More sets 1", L"'[^']*'", L"I have here a '' between quotes", L"''");
    do_test(L"More sets 2", L"[a-z][a-z]* *: *[1-9][0-9]*", L"key:15 # comment", L"key:15");
    do_test(L"More sets 3", L"[a-z][a-z]* *: *[1-9][0-9]*", L"key : 123456 # comment", L"key : 123456");
    do_test(L"More sets 4", L"[a-z][a-z]* *: *[1-9][0-9]*", L"k: 6000", L"k: 6000");
    do_test(L"More sets 5", L"[a-z][a-z]* *: *[1-9][0-9]*", L"key: 1", L"key: 1");
    do_test(L"More sets 6", L"[1-9][0-9]*", L"6000", L"6000");

    do_test(L"Brace matches 1 (like ?)", L"https{0,1}://",  L"http://triptico.com", L"http://");
    do_test(L"Brace matches 2 (like ?)", L"https{0,1}://",  L"https://triptico.com", L"https://");
    do_test(L"Brace matches 3 (like *)", L"a{0,}bc",        L"aaabc", L"aaabc");
    do_test(L"Brace matches 4 (like +)", L"one {1,}world",  L"oneworld", L"");
    do_test(L"Brace matches 5 (like +)", L"one {1,}world",  L"one world", L"one world");
    do_test(L"Brace matches 6 (like +)", L"one {1,}world",  L"one    world", L"one    world");

    do_test(L"Brace matches 11", L"a.{0,5}c",               L"abc", L"abc");
    do_test(L"Brace matches 12", L"a.{0,5}c",               L"abcdec", L"abc");
    do_test(L"Brace matches 13", L"a.{0,5}c",               L"abcdecfghic", L"abc");

    do_test(L"Brace matches 20", L".{5}",                   L"abcdefghijklmnopqrs", L"abcde");

    do_test(L"More * at the end", L"a*", L"", L"");

    return test_summary();
}
Beispiel #17
0
void test_mpsl3(void)
{
    mpdm_t v;

    v = do_test_mpsl("v=[10,20]; w=v[0]; w;");
    mpdm_dump(v);
    v = do_test_exec(v, NULL);
    mpdm_dump(v);

    /* library functions tests */
    v = do_test_mpsl("dump( [1, 2, 3, 4, 5] );");
    do_test_exec(v, NULL);

    v = do_test_mpsl("if(size([2, 3, 4]) == 3) { dump(\"YES\"); } else { dump(\"NO\"); }");
    do_test_exec(v, NULL);

//    v = do_test_mpsl("is_array(1);");
//    do_test("is_array 1", !mpdm_is_true(do_test_exec(v, NULL)));
//    v = do_test_mpsl("is_array([]);");
//    do_test("is_array 2", do_test_exec(v, NULL) != NULL);
//    v = do_test_mpsl("is_array({});");
//    do_test("is_array 3", do_test_exec(v, NULL) != NULL);

//    v = do_test_mpsl("is_hash(1);");
//    do_test("is_hash 1", !mpdm_is_true(do_test_exec(v, NULL)));
//    v = do_test_mpsl("is_hash([]);");
//    do_test("is_hash 2", !mpdm_is_true(do_test_exec(v, NULL)));
//    v = do_test_mpsl("is_hash({});");
//    do_test("is_hash 3", do_test_exec(v, NULL) != NULL);


/*    v = do_test_mpsl("v=splice(\"inventions of life\", NULL, 0, 10); v[1];");
    v = do_test_exec(v, NULL);
    do_test("splice 1", mpdm_cmp(v, MPDM_S(L"inventions")) == 0);

    v = do_test_mpsl("v[0];");
    v = do_test_exec(v, NULL);
    do_test("splice 2", mpdm_cmp(v, MPDM_S(L" of life")) == 0);
*/
    v = do_test_mpsl("sub func() { if(1 == 1) { return(6); 24; } 12; }");
    v = do_test_exec(v, NULL);
    v = do_test_mpsl("a=func();");
    v = do_test_exec(v, NULL);
    do_test("return 1", mpdm_ival(v) == 6);

    v = do_test_mpsl("a=func(); 500;");
    v = do_test_exec(v, NULL);
    do_test("return 2", mpdm_ival(v) == 500);

    v = do_test_mpsl("sub func() { while(1 == 1) { return(6); 24; } 12; }");
    v = do_test_exec(v, NULL);
    v = do_test_mpsl("a=func();");
    v = do_test_exec(v, NULL);
    do_test("return 3", mpdm_ival(v) == 6);

    v = do_test_mpsl("sub func() { foreach(a, [1 .. 10]) { return(6); 24; } 12; }");
    v = do_test_exec(v, NULL);
    v = do_test_mpsl("a=func();");
    v = do_test_exec(v, NULL);
    do_test("return 4", mpdm_ival(v) == 6);

    v = do_test_mpsl("a=1; while(a < 10) { a++; } a;");
    v = do_test_exec(v, NULL);
    do_test("while", mpdm_ival(v) == 10);

    v = do_test_mpsl("a=1; while(a < 10) { if(a == 5) break; a++; } a;");
    v = do_test_exec(v, NULL);
    do_test("break", mpdm_ival(v) == 5);

    v = do_test_mpsl("b=0; foreach(a, [1, 2, 3, 4]) { dump(a); b += a; } return(b);");
    v = do_test_exec(v, NULL);
    do_test("foreach", mpdm_ival(v) == 10);

    v = do_test_mpsl("b=0; foreach(a, [1 .. 20]) { dump(a); b += a; } return(b);");
    v = do_test_exec(v, NULL);
    do_test("foreach+range 1", mpdm_ival(v) == 210);

    v = do_test_mpsl("b=0; foreach(a, [20 .. 1]) { dump(a); b += a; } return(b);");
    v = do_test_exec(v, NULL);
    do_test("foreach+range 2", mpdm_ival(v) == 210);

    v = do_test_mpsl("print(\"print: \", 1, 2, [1, 2, 3], func(), 4);");
    v = do_test_exec(v, NULL);

    v = do_test_mpsl("'This is\\na string.';");
    v = do_test_exec(v, NULL);
    mpdm_dump(v);

    v = do_test_mpsl("\"This is\\na string.\";");
    v = do_test_exec(v, NULL);
    mpdm_dump(v);

    v = do_test_mpsl("sub t(h) { dump(h); dump(h.x); h.x; } H={}; H.x=5; t(H);");
    v = do_test_exec(v, NULL);
    do_test("Accesing a hash's component passed as argument", mpdm_ival(v) == 5);

/*  mpdm_dump(mpdm_root());*/
}
Beispiel #18
0
/* Check that client is sending register refresh */
static int keep_alive_test(const pj_str_t *registrar_uri)
{
    enum { TIMEOUT = 40 };
    struct registrar_cfg server_cfg = 
	/* respond	code	auth	  contact  exp_prm expires more_contacts */
	{ PJ_TRUE,	200,	PJ_FALSE, EXACT,   TIMEOUT, 0,	    {NULL, 0}};
    struct client client_cfg = 
	/* error	code	have_reg    expiration	contact_cnt auth?    destroy*/
	{ PJ_FALSE,	200,	PJ_TRUE,    TIMEOUT,	1,	    PJ_FALSE,PJ_FALSE};
    pj_str_t contact = pj_str("<sip:c@C>");


    pjsip_regc *regc;
    unsigned i;
    int ret;

    ret = do_test("register refresh (takes ~40 secs)", &server_cfg, &client_cfg, registrar_uri,
		  1, &contact, TIMEOUT, PJ_TRUE, &regc);
    if (ret != 0)
	return ret;

    /* Reset server response_cnt */
    registrar.response_cnt = 0;

    /* Wait until keep-alive/refresh is done */
    for (i=0; i<(TIMEOUT-1)*10 && registrar.response_cnt==0; ++i) {
	flush_events(100);
    }

    if (registrar.response_cnt==0) {
	PJ_LOG(3,(THIS_FILE, "    error: no refresh is received"));
	return -400;
    }

    if (client_result.error) {
	PJ_LOG(3,(THIS_FILE, "    error: got error"));
	return -410;
    }
    if (client_result.code != 200) {
	PJ_LOG(3,(THIS_FILE, "    error: expecting code=%d, got code=%d",
		  200, client_result.code));
	return -420;
    }
    if (client_result.expiration != TIMEOUT) {
	PJ_LOG(3,(THIS_FILE, "    error: expecting expiration=%d, got expiration=%d",
		  TIMEOUT, client_result.expiration));
	return -440;
    }
    if (client_result.contact_cnt != 1) {
	PJ_LOG(3,(THIS_FILE, "    error: expecting contact_cnt=%d, got contact_cnt=%d",
		  TIMEOUT, client_result.contact_cnt));
	return -450;
    }
    if (client_result.have_reg == 0) {
	PJ_LOG(3,(THIS_FILE, "    error: expecting have_reg=%d, got have_reg=%d",
		  1, client_result.have_reg));
	return -460;
    }
    if (client_result.interval != TIMEOUT) {
	PJ_LOG(3,(THIS_FILE, "    error: interval (%d) is different than expiration (%d)",
		  client_result.interval, TIMEOUT));
	return -470;
    }
    if (client_result.expiration > 0 && client_result.next_reg < 1) {
	PJ_LOG(3,(THIS_FILE, "    error: next_reg=%d, expecting positive number because expiration is %d",
		  client_result.next_reg, client_result.expiration));
	return -480;
    }

    /* Success */
    pjsip_regc_destroy(regc);
    return 0;
}
Beispiel #19
0
static int
test_main (void)
{
  size_t i;

  test_init ();

  printf ("%23s", "");
  FOR_EACH_IMPL (impl, 0)
    printf ("\t%s", impl->name);
  putchar ('\n');

  for (i = 0; i < 14; ++i)
    {
      do_test (0, 32, 1 << i);
      do_test (32, 0, 1 << i);
      do_test (0, i, 1 << i);
      do_test (i, 0, 1 << i);
    }

  for (i = 0; i < 32; ++i)
    {
      do_test (0, 32, i);
      do_test (32, 0, i);
      do_test (0, i, i);
      do_test (i, 0, i);
    }

  for (i = 3; i < 32; ++i)
    {
      if ((i & (i - 1)) == 0)
	continue;
      do_test (0, 32, 16 * i);
      do_test (32, 0, 16 * i);
      do_test (0, i, 16 * i);
      do_test (i, 0, 16 * i);
    }

  for (i = 32; i < 64; ++i)
    {
      do_test (0, 0, 32 * i);
      do_test (i, 0, 32 * i);
      do_test (0, i, 32 * i);
      do_test (i, i, 32 * i);
    }

  return ret;
}
Beispiel #20
0
/* Send error on refresh */
static int update_test(const pj_str_t *registrar_uri)
{
    enum { TIMEOUT = 40 };
    struct registrar_cfg server_cfg = 
	/* respond	code	auth	  contact  exp_prm expires more_contacts */
	{ PJ_TRUE,	200,	PJ_FALSE, EXACT,   TIMEOUT, 0,	    {NULL, 0}};
    struct client client_cfg = 
	/* error	code	have_reg    expiration	contact_cnt auth?    destroy*/
	{ PJ_FALSE,	200,	PJ_TRUE,    TIMEOUT,	1,	    PJ_FALSE,PJ_FALSE};
    pj_str_t contacts[] = {
	{ "<sip:a>", 7 },
	{ "<sip:b>", 7 },
	{ "<sip:c>", 7 }
    };

    pjsip_regc *regc;
    pjsip_contact_hdr *h1, *h2;
    pjsip_sip_uri *u1;
    unsigned i;
    pj_status_t status;
    pjsip_tx_data *tdata = NULL;
    int ret = 0;

    /* initially only has 1 contact */
    ret = do_test("update test", &server_cfg, &client_cfg, registrar_uri,
		  1, &contacts[0], TIMEOUT, PJ_TRUE, &regc);
    if (ret != 0) {
	return -600;
    }

    /*****
     * replace the contact with new one 
     */
    PJ_LOG(3,(THIS_FILE, "   replacing contact"));
    status = pjsip_regc_update_contact(regc, 1, &contacts[1]);
    if (status != PJ_SUCCESS) {
	ret = -610;
	goto on_return;
    }

    status = pjsip_regc_register(regc, PJ_TRUE, &tdata);
    if (status != PJ_SUCCESS) {
	ret = -620;
	goto on_return;
    }

    /* Check that the REGISTER contains two Contacts:
     *  - <sip:a>;expires=0,
     *  - <sip:b>
     */
    h1 = (pjsip_contact_hdr*) 
	  pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
    if (!h1) {
	ret = -630;
	goto on_return;
    }
    if ((void*)h1->next == (void*)&tdata->msg->hdr)
	h2 = NULL;
    else
	h2 = (pjsip_contact_hdr*) 
	      pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, h1->next);
    if (!h2) {
	ret = -640;
	goto on_return;
    }
    /* must not have other Contact header */
    if ((void*)h2->next != (void*)&tdata->msg->hdr &&
	pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, h2->next) != NULL)
    {
	ret = -645;
	goto on_return;
    }

    u1 = (pjsip_sip_uri*) pjsip_uri_get_uri(h1->uri);

    if (*u1->host.ptr == 'a') {
	if (h1->expires != 0) {
	    ret = -650;
	    goto on_return;
	}
	if (h2->expires == 0) {
	    ret = -660;
	    goto on_return;
	}

    } else {
	pj_assert(*u1->host.ptr == 'b');
	if (h1->expires == 0) {
	    ret = -670;
	    goto on_return;
	}
	if (h2->expires != 0) {
	    ret = -680;
	    goto on_return;
	}
    }

    /* Destroy tdata */
    pjsip_tx_data_dec_ref(tdata);
    tdata = NULL;



    /** 
     * First loop, it will update with more contacts. Second loop
     * should do nothing.
     */
    for (i=0; i<2; ++i) {
	if (i==0)
	    PJ_LOG(3,(THIS_FILE, "   replacing with more contacts"));
	else
	    PJ_LOG(3,(THIS_FILE, "   updating contacts with same contacts"));

	status = pjsip_regc_update_contact(regc, 2, &contacts[1]);
	if (status != PJ_SUCCESS) {
	    ret = -710;
	    goto on_return;
	}

	status = pjsip_regc_register(regc, PJ_TRUE, &tdata);
	if (status != PJ_SUCCESS) {
	    ret = -720;
	    goto on_return;
	}

	/* Check that the REGISTER contains two Contacts:
	 *  - <sip:b>
	 *  - <sip:c>
	 */
	h1 = (pjsip_contact_hdr*) 
	      pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
	if (!h1) {
	    ret = -730;
	    goto on_return;
	}
	if ((void*)h1->next == (void*)&tdata->msg->hdr)
	    h2 = NULL;
	else
	    h2 = (pjsip_contact_hdr*) 
		  pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, h1->next);
	if (!h2) {
	    ret = -740;
	    goto on_return;
	}
	/* must not have other Contact header */
	if ((void*)h2->next != (void*)&tdata->msg->hdr &&
	    pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, h2->next) != NULL)
	{
	    ret = -745;
	    goto on_return;
	}

	/* both contacts must not have expires=0 parameter */
	if (h1->expires == 0) {
	    ret = -750;
	    goto on_return;
	}
	if (h2->expires == 0) {
	    ret = -760;
	    goto on_return;
	}

	/* Destroy tdata */
	pjsip_tx_data_dec_ref(tdata);
	tdata = NULL;
    }

on_return:
    if (tdata) pjsip_tx_data_dec_ref(tdata);
    pjsip_regc_destroy(regc);
    return ret;
};
Beispiel #21
0
int
main(int argc, char * argv[]) {
	smcp_t smcp;
	const char* url = "coap://localhost/";
	int errorcount = 0;
	int round_count = 1;
	int round = 0;
	test_data_s test_data;

	SMCP_LIBRARY_VERSION_CHECK();

	smcp = smcp_create();

	smcp_plat_bind_to_port(smcp, SMCP_SESSION_TYPE_UDP, 0);


//	url = "coap://contiki.local./";
//	url = "coap://coap.me/";
//	url = "coap://vs0.inf.ethz.ch/";

	if (argc > 1) url = argv[1];
	if (!smcp) {
		fprintf(stderr,"Unable to allocate smcp instance\n");
		exit(-1);
	}

	if (argc > 2) {
		round_count = atoi(argv[2]);
	}

	printf("Client using port %d. Will test %d rounds.\n", smcp_plat_get_port(smcp), round_count);

#define do_test(x)	do { printf("%s: Testing...\n",#x); if(test_ ## x(smcp,url,&test_data)) { dump_test_results(&test_data); printf("\tresult = OK\n"); } else { dump_test_results(&test_data); printf("\tresult = FAIL\n"); errorcount++; } } while(0)

#define do_test_expect_fail(x)	do { printf("%s: Testing...\n",#x); if(test_ ## x(smcp,url,&test_data)) { dump_test_results(&test_data); printf("\tresult = OK (Unexpected)\n"); } else { dump_test_results(&test_data); printf("\tresult = FAIL (Expected)\n"); } } while(0)

	for(round = 0;round<round_count && errorcount==0;round++) {
		printf("\n## Round %d...\n",round+1);

		do_test(TD_COAP_CORE_01);
		do_test(TD_COAP_CORE_02);
		do_test(TD_COAP_CORE_03);
		do_test(TD_COAP_CORE_04);
		do_test(TD_COAP_CORE_05);
		do_test(TD_COAP_CORE_06);
		do_test(TD_COAP_CORE_07);
		do_test(TD_COAP_CORE_08);
		do_test(TD_COAP_CORE_09);

		do_test(TD_COAP_CORE_13);
		do_test(TD_COAP_CORE_14);
		do_test(TD_COAP_CORE_17);
		do_test(TD_COAP_CORE_31);

		do_test(TD_COAP_LINK_01);

		do_test(TD_COAP_BLOCK_01);
		do_test(TD_COAP_BLOCK_02);

		do_test_expect_fail(TD_COAP_BLOCK_03);
		do_test_expect_fail(TD_COAP_BLOCK_04);
		do_test_expect_fail(TD_COAP_BLOCK_05);
		do_test(TD_COAP_OBS_01);
	}

	if (errorcount == 0) {
		printf("\nPASS\n");
	} else {
		printf("\nFAIL\n");
	}

	return errorcount;
}
Beispiel #22
0
int regc_test(void)
{
    struct test_rec {
	unsigned		 check_contact;
	unsigned		 add_xuid_param;

	const char		*title;
	char			*alt_registrar;
	unsigned		 contact_cnt;
	char			*contacts[4];
	unsigned		 expires;
	struct registrar_cfg	 server_cfg;
	struct client		 client_cfg;
    } test_rec[] = 
    {
	/* immediate error */
	{
	    OFF,			    /* check_contact	*/
	    OFF,			    /* add_xuid_param	*/
	    "immediate error",		    /* title		*/
	    "sip:unresolved-host-xyy",	    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "sip:[email protected]:5060" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_FALSE,	200,	PJ_FALSE, NONE,	    0,	    0,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	502,	PJ_FALSE,   600,	0,	    PJ_FALSE}
	},

	/* timeout test */
	{
	    OFF,			    /* check_contact	*/
	    OFF,			    /* add_xuid_param	*/
	    "timeout test (takes ~32 secs)",/* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "sip:[email protected]:5060" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_FALSE,	200,	PJ_FALSE, NONE,	    0,	    0,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth? */
	    { PJ_FALSE,	408,	PJ_FALSE,   600,	0,	    PJ_FALSE}
	},

	/* Basic successful registration scenario:
	 * a good registrar returns the Contact header as is and
	 * add expires parameter. In this test no additional bindings
	 * are returned.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "basic",			    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060;transport=udp;x-param=1234>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact  exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, EXACT,    75,	    65,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    75,		1,	    PJ_FALSE}
	},

	/* Basic successful registration scenario with authentication
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "authentication",		    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060;transport=udp;x-param=1234>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact  exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_TRUE,  EXACT,    75,	    65,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    75,		1,	    PJ_TRUE}
	},

	/* a good registrar returns the Contact header as is and
	 * add expires parameter. Also it adds bindings from other
	 * clients in this test.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON,				    /* add_xuid_param	*/
	    "more bindings in response",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060;transport=udp>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact  exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, EXACT,   75,	    65,	    {"<sip:a@a>;expires=70", 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    75,		2,	    PJ_FALSE}
	},


	/* a bad registrar returns modified Contact header, but it
	 * still returns all parameters intact. In this case
	 * the expiration is taken from the expires param because
	 * of matching xuid param or because the number of
	 * Contact header matches.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "registrar modifies Contact header",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, MODIFIED, 75,	    65,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    75,		1,	    PJ_FALSE}
	},


	/* a bad registrar returns modified Contact header, but it
	 * still returns all parameters intact. In addition it returns
	 * bindings from other clients.
	 *
	 * In this case the expiration is taken from the expires param 
	 * because add_xuid_param is enabled.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON,				    /* add_xuid_param	*/
	    "registrar modifies Contact header and add bindings",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, MODIFIED, 75,	    65,	    {"<sip:a@a>;expires=70", 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    75,		2,	    PJ_FALSE}
	},


	/* a bad registrar returns completely different Contact and
	 * all parameters are gone. In this case the expiration is 
	 * also taken from the expires param since the number of 
	 * header matches.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "registrar replaces Contact header",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	202,	PJ_FALSE, NONE,	    0,	    65,	    {"<sip:a@A>;expires=75", 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	202,	PJ_TRUE,    75,		1,	    PJ_FALSE}
	},


	/* a bad registrar returns completely different Contact (and
	 * all parameters are gone) and it also includes bindings from
	 * other clients.
	 * In this case the expiration is taken from the Expires header.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    " as above with additional bindings",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, NONE,	    0,	    65,	    {"<sip:a@A>;expires=75, <sip:b@B;expires=70>", 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    65,		2,	    PJ_FALSE}
	},

	/* the registrar doesn't return any bindings, but for some
	 * reason it includes an Expires header.
	 * In this case the expiration is taken from the Expires header.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "no Contact but with Expires",  /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },  /* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, NONE,	    0,	    65,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    65,		0,	    PJ_FALSE}
	},

	/* Neither Contact header nor Expires header are present.
	 * In this case the expiration is taken from the request.
	 */
	{
	    ON_OFF,			    /* check_contact	*/
	    ON_OFF,			    /* add_xuid_param	*/
	    "no Contact and no Expires",    /* title		*/
	    NULL,			    /* alt_registrar	*/
	    1,				    /* contact cnt	*/
	    { "<sip:[email protected]:5060>" },/* contacts[]	*/
	    600,			    /* expires		*/

	    /* registrar config: */
	    /* respond	code	auth	  contact   exp_prm expires more_contacts */
	    { PJ_TRUE,	200,	PJ_FALSE, NONE,	    0,	    0,	    {NULL, 0}},

	    /* client expected results: */
	    /* error	code	have_reg    expiration	contact_cnt auth?*/
	    { PJ_FALSE,	200,	PJ_TRUE,    600,	0,	    PJ_FALSE}
	},
    };

    unsigned i;
    pj_sockaddr_in addr;
    pjsip_transport *udp = NULL;
    pj_uint16_t port; 
    char registrar_uri_buf[80];
    pj_str_t registrar_uri;
    int rc = 0;

    pj_sockaddr_in_init(&addr, 0, 0);

    /* Acquire existing transport, if any */
    rc = pjsip_endpt_acquire_transport(endpt, PJSIP_TRANSPORT_UDP, &addr, sizeof(addr), NULL, &udp);
    if (rc == PJ_SUCCESS) {
	port = pj_sockaddr_get_port(&udp->local_addr);
	pjsip_transport_dec_ref(udp);
	udp = NULL;
    } else {
	rc = pjsip_udp_transport_start(endpt, NULL, NULL, 1, &udp);
	if (rc != PJ_SUCCESS) {
	    app_perror("   error creating UDP transport", rc);
	    rc = -2;
	    goto on_return;
	}

	port = pj_sockaddr_get_port(&udp->local_addr);
    }

    /* Register registrar module */
    rc = pjsip_endpt_register_module(endpt, &registrar.mod);
    if (rc != PJ_SUCCESS) {
	app_perror("   error registering module", rc);
	rc = -3;
	goto on_return;
    }

    /* Register send module */
    rc = pjsip_endpt_register_module(endpt, &send_mod.mod);
    if (rc != PJ_SUCCESS) {
	app_perror("   error registering module", rc);
	rc = -3;
	goto on_return;
    }

    pj_ansi_snprintf(registrar_uri_buf, sizeof(registrar_uri_buf),
		    "sip:127.0.0.1:%d", (int)port);
    registrar_uri = pj_str(registrar_uri_buf);

    for (i=0; i<PJ_ARRAY_SIZE(test_rec); ++i) {
	struct test_rec *t = &test_rec[i];
	unsigned j, x;
	pj_str_t reg_uri;
	pj_str_t contacts[8];

	/* Fill in the registrar address if it's not specified */
	if (t->alt_registrar == NULL) {
	    reg_uri = registrar_uri;
	} else {
	    reg_uri = pj_str(t->alt_registrar);
	}

	/* Build contact pj_str_t's */
	for (j=0; j<t->contact_cnt; ++j) {
	    contacts[j] = pj_str(t->contacts[j]);
	}

	/* Normalize more_contacts field */
	if (t->server_cfg.more_contacts.ptr)
	    t->server_cfg.more_contacts.slen = strlen(t->server_cfg.more_contacts.ptr);

	/* Do tests with three combinations:
	 *  - check_contact on/off
	 *  - add_xuid_param on/off
	 *  - destroy_on_callback on/off
	 */
	for (x=1; x<=2; ++x) {
	    unsigned y;

	    if ((t->check_contact & x) == 0)
		continue;

	    pjsip_cfg()->regc.check_contact = (x-1);

	    for (y=1; y<=2; ++y) {
		unsigned z;

		if ((t->add_xuid_param & y) == 0)
		    continue;

		pjsip_cfg()->regc.add_xuid_param = (y-1);

		for (z=0; z<=1; ++z) {
		    char new_title[200];

		    t->client_cfg.destroy_on_cb = z;

		    sprintf(new_title, "%s [check=%d, xuid=%d, destroy=%d]", 
			    t->title, pjsip_cfg()->regc.check_contact,
			    pjsip_cfg()->regc.add_xuid_param, z);
		    rc = do_test(new_title, &t->server_cfg, &t->client_cfg, 
				 &reg_uri, t->contact_cnt, contacts, 
				 t->expires, PJ_FALSE, NULL);
		    if (rc != 0)
			goto on_return;
		}

	    }
	}

	/* Sleep between test groups to avoid using up too many
	 * active transactions.
	 */
	pj_thread_sleep(1000);
    }

    /* keep-alive test */
    rc = keep_alive_test(&registrar_uri);
    if (rc != 0)
	goto on_return;

    /* Send error on refresh without destroy on callback */
    rc = refresh_error(&registrar_uri, PJ_FALSE);
    if (rc != 0)
	goto on_return;

    /* Send error on refresh, destroy on callback */
    rc = refresh_error(&registrar_uri, PJ_TRUE);
    if (rc != 0)
	goto on_return;

    /* Updating contact */
    rc = update_test(&registrar_uri);
    if (rc != 0)
	goto on_return;

    /* Send error during auth, don't destroy on callback */
    rc = auth_send_error(&registrar_uri, PJ_FALSE);
    if (rc != 0)
	goto on_return;

    /* Send error during auth, destroy on callback */
    rc = auth_send_error(&registrar_uri, PJ_FALSE);
    if (rc != 0)
	goto on_return;

on_return:
    if (registrar.mod.id != -1) {
	pjsip_endpt_unregister_module(endpt, &registrar.mod);
    }
    if (send_mod.mod.id != -1) {
	pjsip_endpt_unregister_module(endpt, &send_mod.mod);
    }
    if (udp) {
	pjsip_transport_dec_ref(udp);
    }
    return rc;
}
Beispiel #23
0
void fptest2( CYG_ADDRWORD id )
{
    while(1)
        do_test( fpt2_values, FP2_COUNT, 2000000000, id, "fptest2" );
}
Beispiel #24
0
int
test_main (void)
{
  size_t i;

  test_init ();

  printf ("%28s", "");
  FOR_EACH_IMPL (impl, 0)
    printf ("\t%s", impl->name);
  putchar ('\n');

  for (i = 1; i < 8; ++i)
    {
      do_test (i, i, 12, 16, 16, 127);
      do_test (i, i, 23, 16, 16, 255);
      do_test (i, 2 * i, 28, 16, 16, 127);
      do_test (2 * i, i, 31, 16, 16, 255);
      do_test (8 - i, 2 * i, 1, 1 << i, 2 << i, 127);
      do_test (2 * i, 8 - i, 17, 2 << i, 1 << i, 127);
      do_test (8 - i, 2 * i, 0, 1 << i, 2 << i, 255);
      do_test (2 * i, 8 - i, i, 2 << i, 1 << i, 255);
    }

  for (i = 1; i < 8; ++i)
    {
      do_test (0, 0, i, 4 << i, 8 << i, 127);
      do_test (0, 0, i, 16 << i, 8 << i, 127);
      do_test (8 - i, 2 * i, i, 4 << i, 8 << i, 127);
      do_test (8 - i, 2 * i, i, 16 << i, 8 << i, 127);
    }

  return ret;
}
Beispiel #25
0
/* Replace main() with `#include "test-skeleton.c"' to fit in glibc.  */
int main(int argc, char **argv)
{
    return do_test();
}
void do_ptr_test(Foo* value, uint32_t id) {
    do_test(value, FooPtr::cast_to_int(value), true, id);
}
Beispiel #27
0
int main(int argc, char **argv)
{
	int opt;
	int len, rc;
	struct sigaction sigact;
	char *rest;
	int oflags = 0;
	int no_tag;

	memset(&sigact, 0, sizeof(sigact));
	sigact.sa_handler = sighandler;

	if (sigaction(SIGALRM, &sigact, NULL) == -1)
		return 1;

	if (sigaction(SIGPIPE, &sigact, NULL) == -1)
		return 1;

	input = stdin;
	output = stdout;
	/* now parsing options with getopt */
	while ((opt = getopt(argc, argv, options)) != EOF) {
		switch (opt) {
		case 'c':
			rc = chdir(optarg);
			if (rc == -1) {
				fprintf(stderr,
					"Can not change dir to %s errno = %d \"%s\"\n",
					optarg, errno, strerror(errno));
				exit(1);
			}
			break;

		case 'q':
			quiet = true;
			break;

		case 'd':
			duperrors = true;
			break;

		case 's':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -s\n");

			oflags |= 1;
			script = true;
			strncpy(server, optarg, MAXSTR);
			break;

		case 'x':
			if ((oflags & 7) != 0)
				show_usage(1,
					   "Can not combine -x and -s/-p/-n\n");

			oflags |= 8;
			script = true;
			input = fopen(optarg, "r");

			if (input == NULL)
				fatal("Could not open %s\n", optarg);
			break;

		case 'n':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -n\n");

			oflags |= 2;
			strncpy(name, optarg, MAXSTR);
			break;

		case 'p':
			if (oflags > 7)
				show_usage(1, "Can not combine -x and -p\n");

			oflags |= 4;
			strncpy(portstr, optarg, MAXSTR);
			port = atoi(optarg);
			break;

		case '?':
		case 'h':
		default:
			/* display the help */
			show_usage(0, "Help\n");
		}
	}

	if (oflags > 0 && oflags < 7)
		show_usage(1, "Must specify -s, -p, and -n together\n");

	if (oflags == 7)
		openserver();

	while (1) {
		len = readln(input, line, MAXSTR * 2);
		if (len < 0) {
			if (script)
				fatal("End of file on input\n");
			else
				break;
		} else {
			struct response resp;

			lno++;
			memset(&resp, 0, sizeof(resp));

			rest = SkipWhite(line, REQUIRES_MORE, "Invalid line");

			/* Skip totally blank line */
			if (rest == NULL)
				continue;

			if (script && !quiet)
				fprintf(stdout, "%s\n", rest);

			/* If line doesn't start with a tag, that's ok */
			no_tag = (!isdigit(*rest) && (*rest != '$'));

			/* Parse request into response structure */
			rest = parse_request(rest, &resp, no_tag);

			if (rest == NULL) {
				resp.r_status = STATUS_ERRNO;
				resp.r_errno = errno;
			} else {
				/* Make sure default status is ok */
				resp.r_status = STATUS_OK;

				if (*rest != '\0' && *rest != '#')
					fprintf_stderr(
					     "Command line not consumed, rest=\"%s\"\n",
					     rest);

				switch (resp.r_cmd) {
				case CMD_OPEN:
					do_open(&resp);
					break;
				case CMD_CLOSE:
					do_close(&resp);
					break;
				case CMD_LOCKW:
					do_lock(&resp);
					break;
				case CMD_LOCK:
					do_lock(&resp);
					break;
				case CMD_UNLOCK:
					do_unlock(&resp);
					break;
				case CMD_TEST:
					do_test(&resp);
					break;
				case CMD_LIST:
					do_list(&resp);
					break;
				case CMD_HOP:
					do_hop(&resp);
					break;
				case CMD_UNHOP:
					do_unhop(&resp);
					break;
				case CMD_SEEK:
					do_seek(&resp);
					break;
				case CMD_READ:
					do_read(&resp);
					break;
				case CMD_WRITE:
					do_write(&resp);
					break;
				case CMD_ALARM:
					do_alarm(&resp);
					break;

				case CMD_HELLO:
				case CMD_COMMENT:
				case CMD_QUIT:
					resp.r_status = STATUS_OK;
					break;

				case NUM_COMMANDS:
					fprintf_stderr("Invalid command %s\n",
						       line);
					continue;
				}
			}

			respond(&resp);

			if (resp.r_cmd == CMD_QUIT)
				exit(0);
		}
	}

	return 0;
}
void do_int_test(uint64_t value) {
    do_test(FooPtr::cast_to_ptr(static_cast<uintptr_t>(value)), value, false, 0);
}
Beispiel #29
0
int main(int argc UNUSED, char *argv[])
{
	tool_init_log(argv[0]);

	/*
	 * Need to ensure that NSS is initialized before calling
	 * ike_alg_init().  Some sanity checks require a working NSS.
	 */
	lsw_nss_buf_t err;
	if (!lsw_nss_setup(NULL, 0, NULL, err)) {
		fprintf(stderr, "unexpected %s\n", err);
		exit(1);
	}

	ike_alg_init();

	/* esp= */
	fprintf(stdout, "\n---- ESP tests that should succeed ----\n");

	do_test("aes_gcm_a-128-null", PROTO_IPSEC_ESP);
	do_test("3des-sha1;modp1024", PROTO_IPSEC_ESP);
	do_test("3des-sha1;modp1536", PROTO_IPSEC_ESP);
	do_test("3des-sha1;modp2048", PROTO_IPSEC_ESP);
	do_test("3des-sha1;dh22", PROTO_IPSEC_ESP);
	do_test("3des-sha1;dh23", PROTO_IPSEC_ESP);
	do_test("3des-sha1;dh24", PROTO_IPSEC_ESP);
	do_test("3des-sha1", PROTO_IPSEC_ESP);
	do_test("null-sha1", PROTO_IPSEC_ESP);
	do_test("aes", PROTO_IPSEC_ESP);
	do_test("aes_cbc", PROTO_IPSEC_ESP);
	do_test("aes-sha", PROTO_IPSEC_ESP);
	do_test("aes-sha1", PROTO_IPSEC_ESP);
	do_test("aes-sha2", PROTO_IPSEC_ESP);
	do_test("aes-sha256", PROTO_IPSEC_ESP);
	do_test("aes-sha384", PROTO_IPSEC_ESP);
	do_test("aes-sha512", PROTO_IPSEC_ESP);
	do_test("aes128-sha1", PROTO_IPSEC_ESP);
	do_test("aes128-aes_xcbc", PROTO_IPSEC_ESP);
	do_test("aes192-sha1", PROTO_IPSEC_ESP);
	do_test("aes256-sha1", PROTO_IPSEC_ESP);
	do_test("aes256-sha", PROTO_IPSEC_ESP);
	do_test("aes256-sha2", PROTO_IPSEC_ESP);
	do_test("aes256-sha2_256", PROTO_IPSEC_ESP);
	do_test("aes256-sha2_384", PROTO_IPSEC_ESP);
	do_test("aes256-sha2_512", PROTO_IPSEC_ESP);
	do_test("camellia", PROTO_IPSEC_ESP);
	do_test("camellia128", PROTO_IPSEC_ESP);
	do_test("camellia192", PROTO_IPSEC_ESP);
	do_test("camellia256", PROTO_IPSEC_ESP);
	do_test("aes_ccm_a-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_a-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_a-256-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_b-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_b-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_b-256-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_c-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_c-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_c-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_a-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_a-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_a-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_b-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_b-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_b-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_c-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_c-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_c-256-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm-192-null", PROTO_IPSEC_ESP);
#if 0
	/* these are caught using "aliasing" and rewritten to the above syntax */
	do_test("aes_ccm_8-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_8-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_8-256-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_12-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_12-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_12-256-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_16-128-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_16-192-null", PROTO_IPSEC_ESP);
	do_test("aes_ccm_16-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_8-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_8-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_8-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_12-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_12-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_12-256-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_16-128-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_16-192-null", PROTO_IPSEC_ESP);
	do_test("aes_gcm_16-256-null", PROTO_IPSEC_ESP);
#endif
	/* other */
	do_test("aes_ctr", PROTO_IPSEC_ESP);
	do_test("aesctr", PROTO_IPSEC_ESP);
	do_test("aes_ctr128", PROTO_IPSEC_ESP);
	do_test("aes_ctr192", PROTO_IPSEC_ESP);
	do_test("aes_ctr256", PROTO_IPSEC_ESP);
	do_test("serpent", PROTO_IPSEC_ESP);
	do_test("twofish", PROTO_IPSEC_ESP);
	do_test("mars", PROTO_IPSEC_ESP);
	/*
	 * should this be supported - for now man page says not
	 * do_test("modp1536", PROTO_IPSEC_ESP);
	 */

	fprintf(stdout, "\n---- ESP tests that should fail----\n");

	do_test("3des168-sha1", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("3des-null", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("aes128-null", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("aes224-sha1", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("aes512-sha1", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("aes-sha1555", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("camellia666-sha1", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("blowfish", PROTO_IPSEC_ESP); /* obsoleted */
	do_test("des-sha1", PROTO_IPSEC_ESP); /* obsoleted */
	do_test("aes_ctr666", PROTO_IPSEC_ESP); /* bad key size */
	do_test("aes128-sha2_128", PROTO_IPSEC_ESP); /* _128 does not exist */
	do_test("aes256-sha2_256-4096", PROTO_IPSEC_ESP); /* double keysize */
	do_test("aes256-sha2_256-128", PROTO_IPSEC_ESP); /* now what?? */
	do_test("vanitycipher", PROTO_IPSEC_ESP);
	do_test("ase-sah", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("aes-sah1", PROTO_IPSEC_ESP); /* should get rejected */
	do_test("id3", PROTO_IPSEC_ESP); /* should be rejected; idXXX removed */
	do_test("aes-id3", PROTO_IPSEC_ESP); /* should be rejected; idXXX removed */
	do_test("aes_gcm-md5", PROTO_IPSEC_ESP); /* AEAD must have auth null */

	/* ah= */

	fprintf(stdout, "\n---- AH tests that should succeed ----\n");
	do_test("md5", PROTO_IPSEC_AH);
	do_test("sha", PROTO_IPSEC_AH);
	do_test("sha1", PROTO_IPSEC_AH);
	do_test("sha2", PROTO_IPSEC_AH);
	do_test("sha256", PROTO_IPSEC_AH);
	do_test("sha384", PROTO_IPSEC_AH);
	do_test("sha512", PROTO_IPSEC_AH);
	do_test("sha2_256", PROTO_IPSEC_AH);
	do_test("sha2_384", PROTO_IPSEC_AH);
	do_test("sha2_512", PROTO_IPSEC_AH);
	do_test("aes_xcbc", PROTO_IPSEC_AH);
	do_test("ripemd", PROTO_IPSEC_AH);

	fprintf(stdout, "\n---- AH tests that should fail ----\n");
	do_test("aes-sha1", PROTO_IPSEC_AH);
	do_test("vanityhash1", PROTO_IPSEC_AH);
	do_test("aes_gcm_c-256", PROTO_IPSEC_AH);
	do_test("id3", PROTO_IPSEC_AH); /* should be rejected; idXXX removed */
	do_test("3des", PROTO_IPSEC_AH);
	do_test("null", PROTO_IPSEC_AH);
	do_test("aes_gcm", PROTO_IPSEC_AH);
	do_test("aes_ccm", PROTO_IPSEC_AH);

	/* ike= */

	fprintf(stdout, "\n---- IKE tests that should succeed ----\n");
	do_test("3des-sha1", PROTO_ISAKMP);

	fprintf(stdout, "\n---- IKE tests that should fail ----\n");
	do_test("id2", PROTO_ISAKMP); /* should be rejected; idXXX removed */
	do_test("3des-id2", PROTO_ISAKMP); /* should be rejected; idXXX removed */

	fflush(NULL);
	report_leaks();

	lsw_nss_shutdown();
	tool_close_log();
	exit(0);
}
Beispiel #30
0
int main()
{
    do_test();
    CHECK(0);
    exit(0);
}