Example #1
0
TEST parg_getopt_long_optarg_missing(void)
{
	struct parg_state ps;
	char *argv[] = { "app", "--optarg" };
	int li = -1;

	parg_init(&ps);

	ASSERT_EQ('o', parg_getopt_long(&ps, ARRAY_SIZE(argv), argv, ":", po_def, &li));
	ASSERT_EQ(1, li);
	ASSERT_EQ(NULL, ps.optarg);
	ASSERT_EQ(2, ps.optind);

	ASSERT_EQ(-1, parg_getopt_long(&ps, ARRAY_SIZE(argv), argv, ":", po_def, &li));
	ASSERT_EQ(NULL, ps.optarg);
	ASSERT_EQ(2, ps.optind);

	PASS();
}
Example #2
0
TEST basic_test_sadd_sunion(int _commit)
{
	int retval;

	rlite *db = NULL;
	RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1);
	unsigned char *key = UNSIGN("my key");
	long keylen = strlen((char *)key);
	unsigned char *key2 = UNSIGN("my key2");
	long key2len = strlen((char *)key2);
	unsigned char *datas[2] = {UNSIGN("my data"), UNSIGN("my data2")};
	long dataslen[2] = {strlen((char *)datas[0]), strlen((char *)datas[1]) };
	unsigned char *datas2[3] = {UNSIGN("other data2"), UNSIGN("yet another data"), UNSIGN("my data")};
	long datas2len[3] = {strlen((char *)datas2[0]), strlen((char *)datas2[1]), strlen((char *)datas2[2])};
	unsigned char *keys[2] = {key, key2};
	long keyslen[2] = {keylen, key2len};
	unsigned char **datasunion;
	long *datasunionlen, datasc, i;

	RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL);
	RL_BALANCED();
	RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key2, key2len, 3, datas2, datas2len, NULL);
	RL_BALANCED();

	RL_CALL_VERBOSE(rl_sunion, RL_OK, db, 2, keys, keyslen, &datasc, &datasunion, &datasunionlen);
	EXPECT_LONG(datasc, 4);

	EXPECT_BYTES(datas[1], dataslen[1], datasunion[0], datasunionlen[0]);
	EXPECT_BYTES(datas[0], dataslen[0], datasunion[1], datasunionlen[1]);
	EXPECT_BYTES(datas2[1], datas2len[1], datasunion[2], datasunionlen[2]);
	EXPECT_BYTES(datas2[0], datas2len[0], datasunion[3], datasunionlen[3]);

	for (i = 0; i < datasc; i++) {
		rl_free(datasunion[i]);
	}
	rl_free(datasunion);
	rl_free(datasunionlen);


	rl_close(db);
	PASS();
}
Example #3
0
/*  -----------------------------------------------------------------------------------
 *  Test 6: Q(qr(A)).T * Q(qr(A)) == I 
 *    OK: ||I - Q.T*Q||_1 ~~ n*eps
 */
int test_build_identity(int M, int N, int K, int lb, int verbose)
{
  char *blk = lb > 0 ? "  blk" : "unblk";
  char ct = M == K ? 'M' : 'K';
  armas_x_dense_t A0, C0, tau0, D;
  int ok;
  DTYPE n0;
  armas_conf_t conf = *armas_conf_default();

  armas_x_init(&A0, M, N);
  armas_x_init(&C0, M, M);
  armas_x_init(&tau0, imin(M, N), 1);

  // set source data
  armas_x_set_values(&A0, unitrand, ARMAS_ANY);

  // factorize
  conf.lb = lb;
  armas_x_rqfactor(&A0, &tau0, &conf);

  // compute Q = buildQ(rq(A)), K first columns
  conf.lb = lb;
  if (armas_x_rqbuild(&A0, &tau0, K, &conf) < 0)
    printf("build error: %d\n", conf.error);

  // C0 = Q.T*Q - I
  armas_x_mult(0.0, &C0, 1.0, &A0, &A0, ARMAS_TRANSB, &conf);
  armas_x_diag(&D, &C0, 0);
  armas_x_add(&D, -1.0, &conf);

  n0 = armas_x_mnorm(&C0, ARMAS_NORM_ONE, &conf);

  ok = isOK(n0, N);
  printf("%s: %s Q(rq(A),%c).T * Q(rq(A),%c) == I\n", PASS(ok), blk, ct, ct);
  if (verbose > 0) {
    printf("  || rel error ||_1: %e [%d]\n", n0, ndigits(n0));
  }
  //armas_x_release(&A0);
  armas_x_release(&C0);
  armas_x_release(&tau0);
  return ok;
}
Example #4
0
int main(int argc, char *argv[])
{
	void *fdt;
	int subnode1_offset, subnode2_offset;
	int subsubnode1_offset, subsubnode2_offset, subsubnode2_offset2;
	int ss12_off, ss21_off;

	test_init(argc, argv);
	fdt = load_blob_arg(argc, argv);

	subnode1_offset = check_subnode(fdt, 0, "subnode@1");
	subnode2_offset = check_subnode(fdt, 0, "subnode@2");

	if (subnode1_offset == subnode2_offset)
		FAIL("Different subnodes have same offset");

	check_property_cell(fdt, subnode1_offset, "prop-int", TEST_VALUE_1);
	check_property_cell(fdt, subnode2_offset, "prop-int", TEST_VALUE_2);

	subsubnode1_offset = check_subnode(fdt, subnode1_offset, "subsubnode");
	subsubnode2_offset = check_subnode(fdt, subnode2_offset, "subsubnode@0");
	subsubnode2_offset2 = check_subnode(fdt, subnode2_offset, "subsubnode");

	check_property_cell(fdt, subsubnode1_offset, "prop-int", TEST_VALUE_1);
	check_property_cell(fdt, subsubnode2_offset, "prop-int", TEST_VALUE_2);
	check_property_cell(fdt, subsubnode2_offset2, "prop-int", TEST_VALUE_2);

	if (subsubnode2_offset != subsubnode2_offset2)
		FAIL("Different offsets with and without unit address");

	check_subnode(fdt, subnode1_offset, "ss1");
	ss21_off = fdt_subnode_offset(fdt, subnode2_offset, "ss1");
	if (ss21_off != -FDT_ERR_NOTFOUND)
		FAIL("Incorrectly found ss1 in subnode2");

	ss12_off = fdt_subnode_offset(fdt, subnode1_offset, "ss2");
	if (ss12_off != -FDT_ERR_NOTFOUND)
		FAIL("Incorrectly found ss2 in subnode1");
	check_subnode(fdt, subnode2_offset, "ss2");

	PASS();
}
Example #5
0
bool test_ascii_is_white_space (Test *test)
{
	int i;

	TITLE ();
	for (i = SCHAR_MIN; i <= SCHAR_MAX; i++) {
		if ((char)i == ' ' ||
		    (char)i == '\f' ||
		    (char)i == '\n' ||
		    (char)i == '\r' ||
		    (char)i == '\t' ||
		    (char)i == '\v') {
			CATCH (!ascii_is_white_space ((char)i));
		}
		else {
			CATCH (ascii_is_white_space ((char)i));
		}
	}
	PASS ();
}
Example #6
0
int main(int argc, const char* argv[])
{
	// tell dyld we want to know when images are mapped
	dyld_register_image_state_change_handler(dyld_image_state_dependents_mapped, true, batchMappedHandler);
	dyld_register_image_state_change_handler(dyld_image_state_mapped, false, singleMappedHandler);
	dyld_register_image_state_change_handler(dyld_image_state_terminated, false, singleUnmappedHandler);
	// with batch mode we get notified of existing images, but not with single mode, so re-sync counts
	batchMappedCount=0;
	
	loadAndUnLoad();

	loadAndUnLoad();
	
	if ( (singleMappedCount == batchMappedCount) && (singleMappedCount == singleUnMappedCount) )
		PASS("image-state-change");
	else
		FAIL("image-state-change: batch count=%d, single count=%d", batchMappedCount, singleMappedCount);
		
	return EXIT_SUCCESS;
}
bool test_file_writer_write_args_invalid_argument_2 (Test *test)
{
        FileWriter *writer;
        char *path;

        TITLE ();
        CATCH (!(path = directory_current_path ()));
        CATCH (!string_append (&path, "/stage/file_writer/args"));
        if (file_exists (path)) {
                CATCH (!file_remove (path));
        }
        CATCH (!(writer = file_writer_create (path, FileWriterModeTruncate)));
        CATCH (file_writer_write_args (writer, NULL, "test"));
        CATCH (error_count () == 0);
        CATCH (error_at (0).error != ErrorInvalidArgument);
        CATCH (error_at (0).code != 2);
        file_writer_destroy (writer);
        string_destroy (path);
        PASS ();
}
Example #8
0
TEST test_substr(long strsize, long start, long stop, long startindex, long expectedsize)
{
	int retval;
	unsigned char *data = malloc(sizeof(unsigned char) * strsize), *data2;
	rlite *db = NULL;
	RL_CALL_VERBOSE(rl_open, RL_OK, ":memory:", &db, RLITE_OPEN_READWRITE | RLITE_OPEN_CREATE);

	long page, i, size2;
	for (i = 0; i < strsize; i++) {
		data[i] = i % 123;
	}

	RL_CALL_VERBOSE(rl_multi_string_set, RL_OK, db, &page, data, strsize);
	RL_CALL_VERBOSE(rl_multi_string_getrange, RL_OK, db, page, &data2, &size2, start, stop);
	EXPECT_BYTES(&data[startindex], size2, data2, expectedsize);
	rl_free(data2);
	free(data);
	rl_close(db);
	PASS();
}
Example #9
0
bool test_file_remove (Test *test)
{
	char *path;
	FILE *file;

	TITLE ();
	CATCH (file_remove (NULL));
	CATCH (file_remove ("badpathformat"));
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/remove/file"));
        /* d stage/remove */
	if (!file_exists (path)) {
		CATCH (!(file = fopen (path, "ab+")));
		fclose (file);
	}
	CATCH (!file_remove (path));
	CATCH (file_exists (path));
	string_destroy (path);
	PASS ();
}
TEST decoder_poll_should_expand_short_literal() {
    uint8_t input[] = {0xb3, 0x5b, 0xed, 0xe0 }; //"foo"
    uint8_t output[4];
    heatshrink_decoder *hsd = heatshrink_decoder_alloc(256, 7, 3);
    uint16_t count = 0;

    HSD_sink_res sres = heatshrink_decoder_sink(hsd, input, sizeof(input), &count);
    ASSERT_EQ(HSDR_SINK_OK, sres);

    uint16_t out_sz = 0;
    HSD_poll_res pres = heatshrink_decoder_poll(hsd, output, 4, &out_sz);
    ASSERT_EQ(HSDR_POLL_EMPTY, pres);
    ASSERT_EQ(3, out_sz);
    ASSERT_EQ('f', output[0]);
    ASSERT_EQ('o', output[1]);
    ASSERT_EQ('o', output[2]);

    heatshrink_decoder_free(hsd);
    PASS();
}
bool test_big_int_mul_function_call_3 (Test *test)
{
        BigInt *a, *b, *to;

        TITLE ();
        CATCH (!(a = big_int_create (10000000000000000000ULL)));
        CATCH (!(b = big_int_create (10000000000000000000ULL)));
        CATCH (!(to = big_int_create (0)));
        memory_commit_limit (memory_commit_size () +
                             sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 +
                             sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 +
                             sizeof (size_t) + sizeof (BigInt) + sizeof (size_t) + 32 - 1);
        CATCH (big_int_mul (a, b, to));
        CATCH (error_at (0).error != ErrorFunctionCall);
        CATCH (error_at (0).code != 3);
        big_int_destroy (a);
        big_int_destroy (b);
        big_int_destroy (to);
        PASS ();
}
Example #12
0
TEST parg_reorder_long(void)
{
	char *argv[] = {
		"app", "first", "--reqarg", "--", "foo", "--unknown", "bar",
		"--optarg", "--", "--noarg", "last"
	};
	char *argv_expected[] = {
		"app", "--reqarg", "--", "--unknown", "--optarg", "--",
		"first", "foo", "bar", "--noarg", "last"
	};
	size_t i;

	ASSERT_EQ(6, parg_reorder(ARRAY_SIZE(argv), argv, "", po_def));

	for (i = 0; i < ARRAY_SIZE(argv); ++i) {
		ASSERT_STR_EQ(argv_expected[i], argv[i]);
	}

	PASS();
}
Example #13
0
TEST parg_reorder_short(void)
{
	char *argv[] = {
		"app", "first", "-r", "--", "foo", "-u", "bar", "-o", "--",
		"-n", "last"
	};
	char *argv_expected[] = {
		"app", "-r", "--", "-u", "-o", "--", "first", "foo", "bar",
		"-n", "last"
	};
	size_t i;

	ASSERT_EQ(6, parg_reorder(ARRAY_SIZE(argv), argv, os_def, NULL));

	for (i = 0; i < ARRAY_SIZE(argv); ++i) {
		ASSERT_STR_EQ(argv_expected[i], argv[i]);
	}

	PASS();
}
Example #14
0
TEST update_float32_decimals()
{
  TM_msg dummy;
  char topic[128] = "float32_decimals";
  float buf = -64.1235;
  dummy.type = TM_float32;
  dummy.buffer = (void *)&buf;
  dummy.size = 1;
  dummy.topic = topic;

  float destination;

  if(!update_f32(&dummy, "float32_decimals",  &destination))
  {
    FAIL();
  }
  ASSERT_EQ_FMT(buf, destination,"%u");

  PASS();
}
Example #15
0
TEST parg_getopt_long_noarg_inline(void)
{
	struct parg_state ps;
	char *argv[] = { "app", "--noarg=arg" };
	int li = -1;

	parg_init(&ps);

	ASSERT_EQ(':', parg_getopt_long(&ps, ARRAY_SIZE(argv), argv, ":", po_def, &li));
	ASSERT_EQ(0, li);
	ASSERT_EQ(NULL, ps.optarg);
	ASSERT_EQ('n', ps.optopt);
	ASSERT_EQ(2, ps.optind);

	ASSERT_EQ(-1, parg_getopt_long(&ps, ARRAY_SIZE(argv), argv, ":", po_def, &li));
	ASSERT_EQ(NULL, ps.optarg);
	ASSERT_EQ(2, ps.optind);

	PASS();
}
Example #16
0
TEST basic_test_sadd_smove(int _commit)
{
	int retval;

	rlite *db = NULL;
	RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1);
	unsigned char *key = UNSIGN("my key");
	long keylen = strlen((char *)key);
	unsigned char *key2 = UNSIGN("my key2");
	long key2len = strlen((char *)key2);
	unsigned char *data = UNSIGN("my data");
	long datalen = strlen((char *)data);
	unsigned char *data2 = UNSIGN("other data2");
	long data2len = strlen((char *)data2);
	unsigned char *datas[2] = {data, data2};
	long dataslen[2] = {datalen, data2len};

	RL_CALL_VERBOSE(rl_sadd, RL_OK, db, key, keylen, 2, datas, dataslen, NULL);
	RL_BALANCED();

	RL_CALL_VERBOSE(rl_smove, RL_NOT_FOUND, db, key, keylen, key2, key2len, (unsigned char *)"new data", 8);
	RL_BALANCED();

	RL_CALL_VERBOSE(rl_smove, RL_OK, db, key, keylen, key2, key2len, data, datalen);
	RL_BALANCED();

	RL_CALL_VERBOSE(rl_sismember, RL_NOT_FOUND, db, key, keylen, data, datalen);
	RL_CALL_VERBOSE(rl_sismember, RL_FOUND, db, key2, key2len, data, datalen);

	RL_CALL_VERBOSE(rl_smove, RL_OK, db, key, keylen, key2, key2len, data2, data2len);
	RL_BALANCED();

	RL_CALL_VERBOSE(rl_sismember, RL_NOT_FOUND, db, key, keylen, data2, data2len);
	RL_CALL_VERBOSE(rl_sismember, RL_FOUND, db, key2, key2len, data2, data2len);

	RL_CALL_VERBOSE(rl_smove, RL_NOT_FOUND, db, key, keylen, key2, key2len, data, datalen);
	RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL);

	rl_close(db);
	PASS();
}
Example #17
0
TEST test_boot_disk_cputrace() {
    const char *homedir = HOMEDIR;
    char *output = NULL;
    asprintf(&output, "%s/a2_cputrace.txt", homedir);
    if (output) {
        unlink(output);
        cpu65_trace_begin(output);
    }

    srandom(0);
    BOOT_TO_DOS();

    cpu65_trace_end();
    disk6_eject(0);

    do {
        uint8_t md[SHA_DIGEST_LENGTH];
        char mdstr0[(SHA_DIGEST_LENGTH*2)+1];

        FILE *fp = fopen(output, "r");
        fseek(fp, 0, SEEK_END);
        long expectedSize = ftell(fp);
        ASSERT(expectedSize == EXPECTED_CPU_TRACE_FILE_SIZE);
        fseek(fp, 0, SEEK_SET);
        unsigned char *buf = malloc(EXPECTED_CPU_TRACE_FILE_SIZE);
        if (fread(buf, 1, EXPECTED_CPU_TRACE_FILE_SIZE, fp) != EXPECTED_CPU_TRACE_FILE_SIZE) {
            ASSERT(false);
        }
        fclose(fp); fp = NULL;
        SHA1(buf, EXPECTED_CPU_TRACE_FILE_SIZE, md);
        FREE(buf);

        sha1_to_str(md, mdstr0);
        ASSERT(strcmp(mdstr0, EXPECTED_CPU_TRACE_SHA) == 0);
    } while(0);

    unlink(output);
    FREE(output);

    PASS();
}
bool test_poll_close_2 (Test *test)
{
        NetPoll *poll;
        NetServer *server;
        NetClientConnection connection;
        NetClient *client;

        TITLE ();
        monitor_success = false;
        close_success = false;
        poll_connection.closed = false;
        poll_connection.socket = 0;
        poll_connection.tag = NULL;
        CATCH (!(server = net_server_create ("127.0.0.1", 8888,
                                             &server_on_connect,
                                             &server_on_error,
                                             NULL)));
        CATCH (!(client = net_client_create (&client_on_connect,
                                             &client_on_connect_error,
                                             &client_on_error,
                                             NULL)));
        connection.ip = "127.0.0.1";
        connection.port = 8888;
        net_client_connect (client, &connection);
        thread_signal_wait (&server_signal);
        CATCH (!(poll = net_poll_create (&on_monitor, &on_close, NULL, NULL)));
        poll_connection.socket = server_socket;
        CATCH (!net_poll_monitor (poll, &poll_connection));
        thread_signal_wait (&monitor_signal);
        CATCH (!monitor_success);
        CATCH (!net_poll_close (poll, &poll_connection));
        thread_signal_wait (&close_signal);
        CATCH (!close_success);
        net_poll_destroy (poll);
        close (server_socket);
        close (client_socket);
        net_server_destroy (server);
        net_client_destroy (client);
        CATCH (error_count () != 0);
        PASS ();
}
/** \brief Signal handler for managing double clicks in multi-pass dialog.
  * \param view Pointer to the GtkTreeView object.
  * \param path The path of the row that was activated.
  * \param column The column where the activation occured.
  * \param data Pointer to the toplevel window.
  *
  * This function is called when the user double clicks on a pass in the
  * multi-pass dialog. This will cause the pass details to be shown.
  */
static void row_activated_cb (GtkTreeView *treeview, GtkTreePath *path,
                              GtkTreeViewColumn *column, gpointer data)
{
    GtkTreeSelection *selection;
    GtkTreeModel     *model;
    GtkTreeIter       iter;
    GtkWidget        *toplevel = GTK_WIDGET (data);
    guint             rownum = 0;
    GSList           *passes = NULL;
    pass_t           *pass = NULL;
    qth_t            *qth;

    (void) path; /* avoid unused parameter compiler warning */
    (void) column; /* avoid unused parameter compiler warning */

    /* get selected satellite */
    selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));

    if (gtk_tree_selection_get_selected (selection, &model, &iter))  {

        /* get data */
        passes = (GSList *) g_object_get_data (G_OBJECT (treeview), "passes");
        qth = (qth_t *) g_object_get_data (G_OBJECT (treeview), "qth");

        gtk_tree_model_get (model, &iter,
                            MULTI_PASS_COL_NUMBER, &rownum,
                            -1);

        /* get selected pass */
        pass = copy_pass (PASS (g_slist_nth_data (passes, rownum)));

        show_pass (pass->satname, qth, pass, toplevel);

    }
    else {
        sat_log_log (SAT_LOG_LEVEL_ERROR,
                     _("%s:%d: There is no selection; skip popup."),
                     __FILE__, __LINE__);
    }

}
TEST data_with_simple_repetition_should_match_with_absurdly_tiny_buffers() {
    heatshrink_encoder *hse = heatshrink_encoder_alloc(8, 3);
    heatshrink_decoder *hsd = heatshrink_decoder_alloc(256, 8, 3);
    uint8_t input[] = {'a', 'b', 'c', 'a', 'b', 'c', 'd', 'a', 'b',
                       'c', 'd', 'e', 'a', 'b', 'c', 'd', 'e', 'f',
                       'a', 'b', 'c', 'd', 'e', 'f', 'g', 'a', 'b',
                       'c', 'd', 'e', 'f', 'g', 'h'};
    uint8_t comp[60];
    uint8_t decomp[60];
    uint16_t count = 0;
    int log = 0;

    if (log) dump_buf("input", input, sizeof(input));
    for (int i=0; i<sizeof(input); i++) {
        ASSERT(heatshrink_encoder_sink(hse, &input[i], 1, &count) >= 0);
    }
    ASSERT_EQ(HSER_FINISH_MORE, heatshrink_encoder_finish(hse));

    uint16_t packed_count = 0;
    do {
        ASSERT(heatshrink_encoder_poll(hse, &comp[packed_count], 1, &count) >= 0);
        packed_count += count;
    } while (heatshrink_encoder_finish(hse) == HSER_FINISH_MORE);

    if (log) dump_buf("comp", comp, packed_count);
    for (int i=0; i<packed_count; i++) {
        HSD_sink_res sres = heatshrink_decoder_sink(hsd, &comp[i], 1, &count);
        //printf("sres is %d\n", sres);
        ASSERT(sres >= 0);
    }

    for (int i=0; i<sizeof(input); i++) {
        ASSERT(heatshrink_decoder_poll(hsd, &decomp[i], 1, &count) >= 0);
    }

    if (log) dump_buf("decomp", decomp, sizeof(input));
    for (int i=0; i<sizeof(input); i++) ASSERT_EQ(input[i], decomp[i]);
    heatshrink_encoder_free(hse);
    heatshrink_decoder_free(hsd);
    PASS();
}
Example #21
0
TEST basic_test_sadd_sunionstore_empty(int _commit)
{
	int retval;

	rlite *db = NULL;
	RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1);
	unsigned char *key = UNSIGN("my key");
	long keylen = strlen((char *)key);
	unsigned char *key2 = UNSIGN("my key2");
	long key2len = strlen((char *)key2);
	long added;

	RL_CALL_VERBOSE(rl_sunionstore, RL_OK, db, key, keylen, 1, &key2, &key2len, &added);
	RL_BALANCED();
	EXPECT_LONG(added, 0);

	RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL);

	rl_close(db);
	PASS();
}
Example #22
0
bool test_file_directory_sub_path (Test *test)
{
	char *path;

	TITLE ();
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/")), "/"), string_destroy (path)); 
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/a")), "/"), string_destroy (path)); 
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/a/b")), "/a"), string_destroy (path)); 
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/a/b/c")), "/a/b"), string_destroy (path));
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/aa")), "/"), string_destroy (path)); 
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/aa/bbb")), "/aa"), string_destroy (path)); 
	string_destroy (path);
	CATCH_CLEAN (!string_equals ((path = directory_sub_path ("/aa/bbb/cccc")), "/aa/bbb"), string_destroy (path)); 
	string_destroy (path);
	PASS ();
}
TEST decoder_poll_should_expand_short_self_overlapping_backref() {
    /* "aaaaa" == (literal, 1), ('a'), (backref, 1 back, 4 bytes) */
    uint8_t input[] = {0xb0, 0x80, 0x01, 0x80};
    uint8_t output[6];
    uint8_t expected[] = {'a', 'a', 'a', 'a', 'a'};
    heatshrink_decoder *hsd = heatshrink_decoder_alloc(256, 8, 7);
    uint16_t count = 0;
    
    HSD_sink_res sres = heatshrink_decoder_sink(hsd, input, sizeof(input), &count);
    ASSERT_EQ(HSDR_SINK_OK, sres);

    uint16_t out_sz = 0;
    (void)heatshrink_decoder_poll(hsd, output, sizeof(output), &out_sz);

    if (0) dump_buf("output", output, out_sz);
    ASSERT_EQ(sizeof(expected), out_sz);
    for (int i=0; i<sizeof(expected); i++) ASSERT_EQ(expected[i], output[i]);

    heatshrink_decoder_free(hsd);
    PASS();
}
Example #24
0
bool test_file_close (Test *test)
{
	Directory *directory;
	File *file;
	char *path;

	TITLE ();
	CATCH (!(path = directory_current_path ()));
	CATCH (!string_append (&path, "/stage/open"));
        /*
                d stage/open
                f f1
         */
	CATCH (!(directory = directory_open (path)));
	string_destroy (path);
	CATCH (!directory_read (directory));
	CATCH (!(file = directory_find_file (directory, "f1")));
	file_close (file);
	directory_close (directory);
	PASS ();
}
TEST ble_adv_parse_scan_records(void) {
    size_t count = 0;
    int err = 0;

    err = ble_adv_parse_scan(adv0_scan, sizeof(adv0_scan), &count, NULL);
    ASSERT_EQ(err, 0);
    ASSERT_EQ(count, 3);
    
    ble_adv_record_t records[3];
    memset(records, 0, sizeof(ble_adv_record_t) * 3);
    err = ble_adv_parse_scan(adv0_scan, sizeof(adv0_scan), &count, records);

    ble_adv_record_type_t expected_types[3] = { ADV_TYPE_FLAGS, ADV_TYPE_UUID_128, ADV_TYPE_MANUFACTURER_DATA };

    int i = 0;
    for (i = 0; i < count; ++i) {
        ASSERT_EQ(records[i].type, expected_types[i]);
    }

    PASS();
}
Example #26
0
TEST basic_test_lpush_llen(int maxsize, int _commit)
{
	int retval;

	rlite *db = NULL;
	unsigned char *value = malloc(sizeof(unsigned char) * 2);
	RL_CALL_VERBOSE(setup_db, RL_OK, &db, _commit, 1);

	unsigned char *key = UNSIGN("my key");
	long keylen = strlen((char *)key);
	value[1] = 0;
	long size;
	RL_CALL_VERBOSE(create, RL_OK, db, key, keylen, maxsize, _commit, 1);

	RL_CALL_VERBOSE(rl_llen, RL_OK, db, key, keylen, &size);
	EXPECT_LONG(size, maxsize);

	free(value);
	rl_close(db);
	PASS();
}
Example #27
0
int main()
{
	for (int i=0; i < 100; ++i) {
		void* handle = dlopen("libfoo.dylib", RTLD_LAZY);
		if ( handle != NULL ) 
			dlclose(handle);
		dlopen("libnotthere.dylib", RTLD_LAZY);
	}
	

	// execute leaks command on myself
	char cmd[512];
	sprintf(cmd, "sudo leaks %u > /dev/null\n", getpid());
	int result = system(cmd);
	if ( result == EXIT_SUCCESS )
		PASS("dlopen-leak");
	else
		FAIL("dlopen-leak");

	return EXIT_SUCCESS;
}
Example #28
0
TEST test_has_key()
{
	rlite *db = NULL;
	int retval;
	const char *filepath = "rlite-test.rld";
	if (access(filepath, F_OK) == 0) {
		unlink(filepath);
	}
	RL_CALL_VERBOSE(rl_open, RL_OK, filepath, &db, RLITE_OPEN_CREATE | RLITE_OPEN_READWRITE);
	unsigned char type = 'C', type2;
	const unsigned char *key = (unsigned char *)"random key";
	long keylen = strlen((char *) key);
	long value = 529, value2;
	RL_CALL_VERBOSE(rl_key_get, RL_NOT_FOUND, db, key, keylen, NULL, NULL, NULL, NULL, NULL);
	RL_CALL_VERBOSE(rl_key_set, RL_OK, db, key, keylen, type, value, 0, 0);
	RL_CALL_VERBOSE(rl_key_get, RL_FOUND, db, key, keylen, &type2, NULL, &value2, NULL, NULL);
	EXPECT_LONG(value, value2);
	EXPECT_INT(type, type2);
	rl_close(db);
	PASS();
}
TEST test_single_threaded_increment() {

    // Allocate new persistent atomic value
    persistent_atomic_value_t *pav = create_persistent_atomic_value(".", "test_persistent_atomic_value.str", PAV_DELETE_IF_EXISTS);
    uint32_t current_value = 0;

    // Test successful CAS
    for (int i = 0; i < NUM_INCREMENTS; i++) {
        ASSERT_EQ(pav->compare_and_swap(pav, current_value, current_value + 1), 0);
        ASSERT_EQ(pav->get_value(pav), current_value + 1);
        current_value++;
    }

    // Test failing CAS
    ASSERT_EQ(pav->compare_and_swap(pav, 0, current_value + 1), -1);
    ASSERT_EQ(pav->get_value(pav), current_value);

    // Cleanup
    pav->destroy(pav);
    PASS();
}
Example #30
0
TEST unicode_case ()
{	
	uint8_t utf8char[4] = {0};
	ssize_t utf8char_len = tm_utf8_char_encode(0x1F4A9, (uint8_t*) &utf8char);
	ASSERT_EQm("utf8 encode", utf8char[0], 0xf0);
	ASSERT_EQm("utf8 encode", utf8char[1], 0x9f);
	ASSERT_EQm("utf8 encode", utf8char[2], 0x92);
	ASSERT_EQm("utf8 encode", utf8char[3], 0xa9);

	uint8_t* pileofuppercasepoo_cmp = NULL;
	tm_utf8_str_toupper(pileofpoo, -1, &pileofuppercasepoo_cmp);
	ASSERT_EQm("ucs2 length", tm_ucs2_str_length(pileofuppercasepoo_cmp, -1), 23);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 2), 'T');
	for (int i = 0; i < strlen((char*) pileofuppercasepoo); i++) {
		ASSERT_EQm("ucs2 equal", pileofuppercasepoo[i], pileofuppercasepoo_cmp[i]);
	}
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 21), 0xd83d);
	ASSERT_EQm("ucs2 charat", tm_ucs2_str_charat(pileofuppercasepoo_cmp, -1, 22), 0xdca9);

	PASS();
}