Ejemplo n.º 1
0
static void setup() {
  ck_assert_ptr_ne(keystore = nuts_keystore_new(NUTS_SESSION_SRV), NULL);

  ck_assert_ptr_ne(handler = nuts_service_create(), NULL);
  env.rw = malloc(sizeof(struct nuts_session_rw));
  ck_assert_int_eq(nuts_session_rw_init(env.rw, NUTS_SESSION_SRV, keystore), 0);

  ck_assert_ptr_ne(buf_s2c = &env.rw->lv[NUTS_WRITE], NULL);
  nuts_lv_clear(buf_s2c);

  nuts_lv_init(&msg_buf);

  payload = NULL;
  npayload = 0;
  cstr = NULL;
  selected_invocations = 0;
  cleanup_invocations = 0;
  tick_invocations = 0;

  ck_assert_int_eq(nuts_service_add_srv_spec(handler, &inval_spec, &test_ctx), 0);
  ck_assert_int_eq(nuts_service_add_srv_spec(handler, &error_spec, &test_ctx), 0);
  ck_assert_int_eq(nuts_service_add_srv_spec(handler, &done_spec, &test_ctx), 0);
  ck_assert_int_eq(nuts_service_add_srv_spec(handler, &continue_spec, &test_ctx), 0);
  ck_assert_int_eq(nuts_service_add_srv_spec(handler, &again_spec, &test_ctx), 0);
}
Ejemplo n.º 2
0
END_TEST

START_TEST(arrayCopyShallMakeADeepCopy) {
	// given
	UA_String a1[3];
	a1[0] = (UA_String){1, (UA_Byte*)"a"};
	a1[1] = (UA_String){2, (UA_Byte*)"bb"};
	a1[2] = (UA_String){3, (UA_Byte*)"ccc"};
	// when
	UA_String *a2;
	UA_Int32   retval = UA_Array_copy((const void *)a1, 3, &UA_TYPES[UA_STRING], (void **)&a2);
	// then
	ck_assert_int_eq(retval, UA_STATUSCODE_GOOD);
	ck_assert_int_eq(a1[0].length, 1);
	ck_assert_int_eq(a1[1].length, 2);
	ck_assert_int_eq(a1[2].length, 3);
	ck_assert_int_eq(a1[0].length, a2[0].length);
	ck_assert_int_eq(a1[1].length, a2[1].length);
	ck_assert_int_eq(a1[2].length, a2[2].length);
	ck_assert_ptr_ne(a1[0].data, a2[0].data);
	ck_assert_ptr_ne(a1[1].data, a2[1].data);
	ck_assert_ptr_ne(a1[2].data, a2[2].data);
	ck_assert_int_eq(a1[0].data[0], a2[0].data[0]);
	ck_assert_int_eq(a1[1].data[0], a2[1].data[0]);
	ck_assert_int_eq(a1[2].data[0], a2[2].data[0]);
	// finally
	UA_Array_delete((void *)a2, 3, &UA_TYPES[UA_STRING]);
}
Ejemplo n.º 3
0
END_TEST

START_TEST (test_expression)
{
    int i;
    expression *e = get_expression("c1, symbol O+C");

    ck_assert_ptr_ne(e,NULL);
    ck_assert_int_eq(e->type, E_SELECTION);
    ck_assert_ptr_ne(e->left, NULL);
    ck_assert_ptr_eq(e->right, NULL);
    ck_assert_str_eq(e->value, "c1");
    ck_assert_int_eq(e->left->type,E_SYMBOL);
    ck_assert_ptr_ne(e->left->left,NULL);
    ck_assert_ptr_eq(e->left->right,NULL);
    ck_assert_int_eq(e->left->left->type,E_PLUS);
    ck_assert_int_eq(e->left->left->left->type,E_ID);
    ck_assert_int_eq(e->left->left->right->type,E_ID);
    ck_assert_str_eq(e->left->left->right->value,"C");
    ck_assert_str_eq(e->left->left->left->value,"O");
    for (i = E_SELECTION; i <= E_RANGE_OPEN_R; ++i) {
        ck_assert_ptr_ne(e_str(i), NULL);
    }
    ck_assert_ptr_eq(e_str(E_RANGE_OPEN_R+1), NULL);
}
Ejemplo n.º 4
0
END_TEST

START_TEST(test_hyperloglog_copy_and_clone)
{
  DESCRIBE_TEST;
  for (uint8_t p = TW_HLL_MIN_PRECISION; p <= TW_HLL_MAX_PRECISION; ++p) {
    const uint32_t n_registers = 1 << p;
    struct tw_hyperloglog *hll = tw_hyperloglog_new(p);
    struct tw_hyperloglog *copy = tw_hyperloglog_new(p);

    /** test linear_count */
    for (size_t k = 0; k < n_registers; ++k) {
      if (k % 2) {
        tw_hyperloglog_add(hll, (void *)&k, sizeof(k));
      }
    }

    ck_assert_ptr_ne(tw_hyperloglog_copy(hll, copy), NULL);
    ck_assert(
        tw_almost_equal(tw_hyperloglog_count(hll), tw_hyperloglog_count(copy)));

    struct tw_hyperloglog *clone = tw_hyperloglog_clone(copy);
    ck_assert_ptr_ne(clone, NULL);
    ck_assert(tw_hyperloglog_equal(hll, clone));
    ck_assert(tw_almost_equal(tw_hyperloglog_count(hll),
                              tw_hyperloglog_count(clone)));

    tw_hyperloglog_free(clone);
    tw_hyperloglog_free(copy);
    tw_hyperloglog_free(hll);
  }
}
Ejemplo n.º 5
0
END_TEST

START_TEST (test_structure)
{
    FILE *file = fopen(DATADIR "1ubq.pdb","r");
    int n;
    freesasa_set_verbosity(FREESASA_V_SILENT);
    ck_assert_ptr_ne(file, NULL);
    ck_assert_ptr_eq(freesasa_structure_new(), NULL);
    ck_assert_ptr_eq(from_pdb_impl(file,interval, NULL, 0), NULL);
    for (int i = 1; i < 100; ++i) {
        set_fail_freq(i);
        rewind(file);
        ck_assert_ptr_eq(freesasa_structure_from_pdb(file, NULL, 0), NULL);
    }
    fclose(file);
    
    file = fopen(DATADIR "2jo4.pdb", "r");
    ck_assert_ptr_ne(file,NULL);
    for (int i = 1; i < 50; ++i) {
        set_fail_freq(i);
        rewind(file);
        ck_assert_ptr_eq(freesasa_structure_array(file, &n, NULL, FREESASA_SEPARATE_MODELS),NULL);
        rewind(file);
        ck_assert_ptr_eq(freesasa_structure_array(file, &n, NULL, FREESASA_SEPARATE_MODELS | FREESASA_SEPARATE_CHAINS),NULL);
    }
    set_fail_freq(1);
    fclose(file);
    freesasa_set_verbosity(FREESASA_V_NORMAL);
}
Ejemplo n.º 6
0
END_TEST

START_TEST(test_osgetelements)
{
    char xml_file_name[256];
    create_xml_file("<root><child1/><child2/></root>", xml_file_name, 256);
    OS_XML xml;
    ck_assert_int_eq(OS_ReadXML(xml_file_name, &xml), 0);
    ck_assert_int_eq(OS_ApplyVariables(&xml), 0);
    const char *xml_path[] = { "root", NULL };
    char **content1, **content2;
    ck_assert_ptr_ne(content1 = OS_GetElements(&xml, xml_path), NULL);
    ck_assert_str_eq(content1[0], "child1");
    ck_assert_str_eq(content1[1], "child2");
    ck_assert_ptr_eq(content1[2], NULL);
    ck_assert_ptr_ne(content2 = OS_GetElements(&xml, NULL), NULL);
    ck_assert_str_eq(content2[0], "root");
    ck_assert_ptr_eq(content2[1], NULL);
    const char *xml_path2[] = { NULL };
    ck_assert_ptr_eq(OS_GetElements(&xml,  xml_path2), NULL);

    int i = 0;
    while (content1[i]) {
        free(content1[i++]);
    }
    free(content1);
    i = 0;
    while (content2[i]) {
        free(content2[i++]);
    }
    free(content2);
    OS_ClearXML(&xml);
    unlink(xml_file_name);
}
Ejemplo n.º 7
0
END_TEST

START_TEST (test_copy_cell)
{
	apr_pool_t* pool = NULL;
    apr_pool_create(&pool, NULL);
	cell* parent = sexpr_cell(pool);
    cell* childa = sym_cell(pool, "a");
    cell* childb = sym_cell(pool, "b");
    cell* childc = sym_cell(pool, "c");	
	
	add_cell(pool, parent, childc);
    add_cell(pool, parent, childb);
    add_cell(pool, parent, childa);

	cell* clone = copy_cell(pool, parent);
	ck_assert_int_eq(3, clone->count);
	cell* clonec = pop_cell(pool, clone, 0);
	ck_assert_ptr_ne(clonec, childc);
	ck_assert_str_eq(clonec->sym, childc->sym);
	cell* cloneb = pop_cell(pool, clone, 0);
	ck_assert_ptr_ne(cloneb, childb);
	ck_assert_str_eq(cloneb->sym, childb->sym);
	cell* clonea = pop_cell(pool, clone, 0);
	ck_assert_ptr_ne(clonea, childa);
	ck_assert_str_eq(clonea->sym, childa->sym);
	ck_assert_int_eq(0, clone->count);	

    apr_pool_destroy(pool);
}
Ejemplo n.º 8
0
END_TEST

START_TEST (test_two_subscribers_and_push_event)
{
    printf("\n-----test_two_subscribers_and_push_event start-----\n");
    sentToCallback = NULL;
    sentToCallback2 = NULL;
    InitEventProcessor();
    int16_t stakeholderId = RegisterStakeholder("teststakeholder");
    eventSubscription_t subscription;
    subscription.stakeholderId = stakeholderId;
    subscription.eventType = EVENT_HEARTBEAT;
    subscription.callback = &test_callback;
    Subscribe(subscription);

    stakeholderId = RegisterStakeholder("teststakeholder2");
    eventSubscription_t subscription2;
    subscription2.stakeholderId = stakeholderId;
    subscription2.callback = &test_callback2;
    subscription2.eventType = EVENT_HEARTBEAT;
    Subscribe(subscription2);

    struct timespec tms;
    clock_gettime(CLOCK_REALTIME, &tms);
    event_t* event = (event_t*)malloc(sizeof(event_t));
    event->timeStamp = tms.tv_sec;
    event->prio = 123;
    event->sourceId = stakeholderId;
    event->eventType = EVENT_HEARTBEAT;
    event->payloadSize = 0;
    event->payload = NULL;

    printf("pushing eventdata ptr=%p, timeStamp=%d, prio=%d, sourceId=%d, eventType=%d, payloadSize=%d, *payload=%p\n", event, event->timeStamp, event->prio, event->sourceId, event->eventType, event->payloadSize, event->payload);

    int rsp = PushEvent(event);
    
    printf("Done with PushEvent, moving on to asserts, waiting for callbacks to be called\n");
    fflush(stdout);

    int waitForCallback = WaitForCallback();
    ck_assert_int_eq (waitForCallback, 0);
    int waitForCallback2 = WaitForCallback2();
    ck_assert_int_eq (waitForCallback2, 0);
    ck_assert_int_eq (rsp, EP_OK); 
    printf("sentToCallback=%p sentToCallback2=%p\n", sentToCallback, sentToCallback2);
    ck_assert_ptr_ne (sentToCallback, (event_t*)0);
    ck_assert_ptr_ne (sentToCallback2, (event_t*)0);
    if ((sentToCallback - sentToCallback2) == 0) ck_abort_msg("Failed! Same event sent to both subscribers");


    int firstEventEqual = CompareEvent(event, sentToCallback); 
    ck_assert_int_eq (firstEventEqual, 0);
    int secondEventEqual = CompareEvent(event, sentToCallback2); 
    ck_assert_int_eq (secondEventEqual, 0);
    printf("-----test_two_subscribers_and_push_event done-----\n\n");
    free(event);
}
Ejemplo n.º 9
0
static void setup() {
  nuts_lv_init(&lv);
  nuts_lv_init(&I_C); nuts_lv_set_cstr(&I_C, "clients KEXINIT payload");
  nuts_lv_init(&I_S); nuts_lv_set_cstr(&I_S, "servers KEXINIT payload");
  nuts_lv_init(&K_S); nuts_lv_set_cstr(&K_S, "the hostkey");
  ck_assert_ptr_ne(e = nuts_mpi_new_ul(1), NULL);
  ck_assert_ptr_ne(f = nuts_mpi_new_ul(2), NULL);
  ck_assert_ptr_ne(K = nuts_mpi_new_ul(3), NULL);
}
Ejemplo n.º 10
0
END_TEST

START_TEST(test_ck_assert_ptr_ne)
{
  int * x = (int*)0x1;
  int * y = (int*)0x2;
  int * z = x;
  ck_assert_ptr_ne(x,    y);
  ck_assert_ptr_ne(x,    NULL);
  ck_assert_ptr_ne(NULL, y);
  ck_assert_ptr_ne(x,    z);
  #define LINENO_ck_assert_ptr_ne _STR(__LINE__)
}
END_TEST

START_TEST(test_curve25519_generate_public)
{
    int result;

    uint8_t alicePublic[] = {
            0x05, 0x1b, 0xb7, 0x59, 0x66,
            0xf2, 0xe9, 0x3a, 0x36, 0x91,
            0xdf, 0xff, 0x94, 0x2b, 0xb2,
            0xa4, 0x66, 0xa1, 0xc0, 0x8b,
            0x8d, 0x78, 0xca, 0x3f, 0x4d,
            0x6d, 0xf8, 0xb8, 0xbf, 0xa2,
            0xe4, 0xee, 0x28};

    uint8_t alicePrivate[] = {
            0xc8, 0x06, 0x43, 0x9d, 0xc9,
            0xd2, 0xc4, 0x76, 0xff, 0xed,
            0x8f, 0x25, 0x80, 0xc0, 0x88,
            0x8d, 0x58, 0xab, 0x40, 0x6b,
            0xf7, 0xae, 0x36, 0x98, 0x87,
            0x90, 0x21, 0xb9, 0x6b, 0xb4,
            0xbf, 0x59};

    ec_private_key *alice_private_key = 0;
    ec_public_key *alice_expected_public_key = 0;
    ec_public_key *alice_public_key = 0;

    /* Initialize Alice's private key */
    result = curve_decode_private_point(&alice_private_key, alicePrivate, sizeof(alicePrivate), global_context);
    ck_assert_int_eq(result, 0);
    ck_assert_ptr_ne(alice_private_key, 0);

    /* Initialize Alice's expected public key */
    result = curve_decode_point(&alice_expected_public_key, alicePublic, sizeof(alicePublic), global_context);
    ck_assert_int_eq(result, 0);
    ck_assert_ptr_ne(alice_expected_public_key, 0);

    /* Generate Alice's actual public key */
    result = curve_generate_public_key(&alice_public_key, alice_private_key);
    ck_assert_int_eq(result, 0);
    ck_assert_ptr_ne(alice_public_key, 0);

    /* Assert that expected and actual public keys match */
    ck_assert_int_eq(ec_public_key_compare(alice_expected_public_key, alice_public_key), 0);

    /* Cleanup */
    SIGNAL_UNREF(alice_public_key);
    SIGNAL_UNREF(alice_expected_public_key);
    SIGNAL_UNREF(alice_private_key);
}
Ejemplo n.º 12
0
END_TEST


START_TEST (test_connects_tcp_and_establishes_protocol)
{
    uint32_t version = htonl(1);
    rb_append(in_rb, &version, sizeof(version));

    neo4j_connection_t *connection = neo4j_tcp_connect(
            "localhost", 7687, config, 0);
    ck_assert_ptr_ne(connection, NULL);
    ck_assert_ptr_eq(connection->iostream, client_ios);

    ck_assert_int_eq(rb_used(out_rb), 20);
    uint8_t expected_hello[4] = { 0x60, 0x60, 0xB0, 0x17 };
    uint8_t hello[4];
    rb_extract(out_rb, hello, 4);
    ck_assert(memcmp(hello, expected_hello, 4) == 0);

    uint32_t expected_versions[4] = { htonl(1), 0, 0, 0 };
    uint32_t versions[4];
    rb_extract(out_rb, versions, 16);
    ck_assert(memcmp(versions, expected_versions, 16) == 0);

    neo4j_close(connection);
}
Ejemplo n.º 13
0
END_TEST


START_TEST (test_connects_URI_containing_credentials)
{
    uint32_t version = htonl(1);
    rb_append(in_rb, &version, sizeof(version));

    username = "******";
    password = "******";
    neo4j_connection_t *connection = neo4j_connect(
            "neo4j://john:smith@localhost:7687", config, 0);
    ck_assert_ptr_ne(connection, NULL);
    ck_assert_ptr_eq(connection->iostream, client_ios);

    ck_assert_int_eq(rb_used(out_rb), 20);
    uint8_t expected_hello[4] = { 0x60, 0x60, 0xB0, 0x17 };
    uint8_t hello[4];
    rb_extract(out_rb, hello, 4);
    ck_assert(memcmp(hello, expected_hello, 4) == 0);

    uint32_t expected_versions[4] = { htonl(1), 0, 0, 0 };
    uint32_t versions[4];
    rb_extract(out_rb, versions, 16);
    ck_assert(memcmp(versions, expected_versions, 16) == 0);

    neo4j_close(connection);
}
Ejemplo n.º 14
0
END_TEST

START_TEST(test_version_string) {
    const struct vca_boilerplate_version * const version = vca_boilerplate_get_version();
    ck_assert_ptr_ne(NULL, version);
    ck_assert_str_eq(version->string, VCA_BOILERPLATE_VERSION_STRING);
}
Ejemplo n.º 15
0
END_TEST

START_TEST(test_version_revision) {
    const struct vca_boilerplate_version * const version = vca_boilerplate_get_version();
    ck_assert_ptr_ne(NULL, version);
    ck_assert_uint_eq(version->revision, VCA_BOILERPLATE_VERSION_REVISION);
}
Ejemplo n.º 16
0
END_TEST

START_TEST(test_version_minor) {
    const struct vca_boilerplate_version * const version = vca_boilerplate_get_version();
    ck_assert_ptr_ne(NULL, version);
    ck_assert_uint_eq(version->minor, VCA_BOILERPLATE_VERSION_MINOR);
}
Ejemplo n.º 17
0
END_TEST

START_TEST(test_jwt_encode_alg_none)
{
	const char res[] = "eyJhbGciOiJub25lIn0.eyJhdWQiOiJ3d3cucGx1Z2dlcnM"
		"ubmwiLCJleHAiOjE0Nzc1MTQ4MTIsInN1YiI6IlBsdWdnZXJzIFNvZnR3YXJlIn0.";
	jwt_t *jwt = NULL;
	int ret = 0;
	char *out;

	ALLOC_JWT(&jwt);

	ret = jwt_add_grant(jwt, "aud", "www.pluggers.nl");
	ck_assert_int_eq(ret, 0);

	ret = jwt_add_grant_int(jwt, "exp", 1477514812);
	ck_assert_int_eq(ret, 0);

	ret = jwt_add_grant(jwt, "sub", "Pluggers Software");
	ck_assert_int_eq(ret, 0);

	ret = jwt_set_alg(jwt, JWT_ALG_NONE, NULL, 0);
	ck_assert_int_eq(ret, 0);

	out = jwt_encode_str(jwt);
	ck_assert_ptr_ne(out, NULL);

	ck_assert_str_eq(out, res);

	free(out);

	jwt_free(jwt);
}
Ejemplo n.º 18
0
void _setup_number_lexer(void) {
  lexa = setup_with_scanners();
  lexa_add_scanner(lexa, "number");
  ck_assert_int_eq(dict_size(lexa -> scanners), 4);
  lexa_build_lexer(lexa);
  ck_assert_ptr_ne(lexa -> config, NULL);
}
Ejemplo n.º 19
0
END_TEST

START_TEST(test_store_load)
{
    int res;
    uproc_matrix *mat;
    size_t rows, cols;
    double data[] = {
        0.0, 0.1, 0.2, 0.3,
        1.0, 1.1, 1.2, 1.3 };

    mat = uproc_matrix_create(2, 4, data);

    res = uproc_matrix_store(mat, UPROC_IO_GZIP, TMPDATADIR "test.matrix");
    ck_assert_msg(res == 0, "storing failed");
    uproc_matrix_destroy(mat);

    mat = uproc_matrix_load(UPROC_IO_GZIP, TMPDATADIR "test.matrix");
    ck_assert_ptr_ne(mat, NULL);

    uproc_matrix_dimensions(mat, &rows, &cols);
    ck_assert_uint_eq(rows, 2);
    ck_assert_uint_eq(cols, 4);

    ck_assert(uproc_matrix_get(mat, 0, 0) == 0.0);
    ck_assert(uproc_matrix_get(mat, 0, 2) == 0.2);
    ck_assert(uproc_matrix_get(mat, 0, 3) == 0.3);
    ck_assert(uproc_matrix_get(mat, 1, 0) == 1.0);
    ck_assert(uproc_matrix_get(mat, 1, 2) == 1.2);
    ck_assert(uproc_matrix_get(mat, 1, 3) == 1.3);
}
Ejemplo n.º 20
0
END_TEST


START_TEST(test_endpoint_contains_region)
{
	AWS_SERVICE service;
	AWS_REGION region;
	HAWSERresult result;
	const char *region_name;
	const char *endpoint;

	for (service = AWS_SERVICE_MIN; service <= AWS_SERVICE_MAX; service++) {
		for (region = AWS_REGION_MIN; region <= AWS_REGION_MAX; region++) {
			result = aws_region(region, &region_name);
			ck_assert_int_eq(HAWSER_OK, result);

			result = aws_endpoint(service, region, &endpoint);

			if (result == HAWSER_BAD_REGION) {
				/* Skip if not supported */
				continue;
			}

			ck_assert_ptr_ne(NULL, strstr(endpoint, region_name));
		}
	}
}
Ejemplo n.º 21
0
END_TEST

START_TEST (test_subscribe_and_push_event)
{
    printf("\n-----test_subscribe_and_push_event start-----\n");
    InitEventProcessor();
    int16_t stakeholderId = RegisterStakeholder("teststakeholder");
    eventSubscription_t subscription;
    subscription.stakeholderId = stakeholderId;
    subscription.eventType = EVENT_HEARTBEAT;
    subscription.callback = test_callback;
    Subscribe(subscription);

    struct timespec tms;
    clock_gettime(CLOCK_REALTIME, &tms);
    event_t* event = (event_t*)malloc(sizeof(event_t));
    event->timeStamp = tms.tv_sec;
    event->prio = 123;
    event->sourceId = stakeholderId;
    event->eventType = EVENT_HEARTBEAT;
    event->payloadSize = 0;
    event->payload = NULL;
    int rsp = PushEvent(event);
    
    int result = WaitForCallback();
    ck_assert_int_eq (result, 0);
    ck_assert_int_eq (rsp, EP_OK); 
    ck_assert_ptr_ne (sentToCallback, (event_t*)0);

    int equality = CompareEvent(event, sentToCallback); 
    ck_assert_int_eq (equality, 0);
    free(event);
    printf("-----test_subscribe_and_push_event done-----\n\n");
}
Ejemplo n.º 22
0
END_TEST

START_TEST(test_jwt_encode_str)
{
	const char res[] = "eyJhbGciOiJub25lIn0.eyJpYXQiOjE0NzU5ODA1NDUsIm"
		"lzcyI6ImZpbGVzLmN5cGhyZS5jb20iLCJyZWYiOiJYWFhYLVlZWVktWlpa"
		"Wi1BQUFBLUNDQ0MiLCJzdWIiOiJ1c2VyMCJ9.";
	jwt_t *jwt = NULL;
	int ret = 0;
	char *out;

	ALLOC_JWT(&jwt);

	ret = jwt_add_grant(jwt, "iss", "files.cyphre.com");
	ck_assert_int_eq(ret, 0);

	ret = jwt_add_grant(jwt, "sub", "user0");
	ck_assert_int_eq(ret, 0);

	ret = jwt_add_grant(jwt, "ref", "XXXX-YYYY-ZZZZ-AAAA-CCCC");
	ck_assert_int_eq(ret, 0);

	ret = jwt_add_grant_int(jwt, "iat", TS_CONST);
	ck_assert_int_eq(ret, 0);

	out = jwt_encode_str(jwt);
	ck_assert_ptr_ne(out, NULL);

	ck_assert_str_eq(out, res);

	free(out);

	jwt_free(jwt);
}
Ejemplo n.º 23
0
END_TEST

START_TEST(test_version_commit) {
    const struct vca_boilerplate_version * const version = vca_boilerplate_get_version();
    ck_assert_ptr_ne(NULL, version);
    ck_assert_str_eq(version->commit, VCA_BOILERPLATE_VERSION_COMMIT);
}
Ejemplo n.º 24
0
END_TEST

#ifdef UA_ENABLE_DISCOVERY_SEMAPHORE

#ifndef WIN32
#define SEMAPHORE_PATH "/tmp/open62541-unit-test-semaphore"
#else
#define SEMAPHORE_PATH ".\\open62541-unit-test-semaphore"
#endif

START_TEST(Server_register_semaphore) {
    // create the semaphore
#ifndef WIN32
    int fd = open(SEMAPHORE_PATH, O_RDWR|O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO);
    ck_assert_int_ne(fd, -1);
    close(fd);
#else
    FILE *fp;
    fopen_s(&fp, SEMAPHORE_PATH, "ab+");
    ck_assert_ptr_ne(fp, NULL);
    fclose(fp);
#endif

    UA_Client *clientRegister = UA_Client_new();
    UA_ClientConfig_setDefault(UA_Client_getConfig(clientRegister));

    UA_StatusCode retval = UA_Client_connect_noSession(clientRegister, "opc.tcp://localhost:4840");
    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
    retval = UA_Server_register_discovery(server_register, clientRegister, SEMAPHORE_PATH);
    ck_assert_uint_eq(retval, UA_STATUSCODE_GOOD);
    UA_Client_disconnect(clientRegister);
    UA_Client_delete(clientRegister);
}
END_TEST

START_TEST(one_consumer_simple)
    {
        void *a = malloc(sizeof(int));
        void *b = malloc(sizeof(int));
        void *c = malloc(sizeof(int));
        void *d = malloc(sizeof(int));
        multiconsumer_buffer_t *m_buffer = mcb_init_buffer(4, 1, 1, free);
        ck_assert_ptr_ne(NULL, m_buffer);
        mcb_write(m_buffer, a);
        mcb_write(m_buffer, b);
        mcb_write(m_buffer, c);

        ck_assert_ptr_eq(a, mcb_read(m_buffer, 0));
        mcb_unref(m_buffer, 0);

        mcb_write(m_buffer, d);

        ck_assert_ptr_eq(b, mcb_read(m_buffer, 0));
        mcb_unref(m_buffer, 0);
        ck_assert_ptr_eq(c, mcb_read(m_buffer, 0));
        mcb_unref(m_buffer, 0);
        ck_assert_ptr_eq(d, mcb_read(m_buffer, 0));
        mcb_unref(m_buffer, 0);

        mcb_destroy(m_buffer);
    }
Ejemplo n.º 26
0
END_TEST

START_TEST(test_bitmap_copy_and_clone)
{
  DESCRIBE_TEST;

  const uint32_t sizes[] = {512, 1024, 2048, 4096};

  for (size_t i = 0; i < TW_ARRAY_SIZE(sizes); ++i) {
    const uint32_t nbits = sizes[i];
    struct tw_bitmap *src = tw_bitmap_new(nbits);
    struct tw_bitmap *dst = tw_bitmap_new(nbits);

    for (uint32_t k = 0; k < nbits; ++k) {
      if (k % 2) {
        tw_bitmap_set(src, k);
      }
    }

    ck_assert_ptr_ne(tw_bitmap_copy(src, dst), NULL);

    struct tw_bitmap *tmp = tw_bitmap_clone(src);

    for (uint32_t k = 0; k < nbits; ++k) {
      if (k % 2) {
        ck_assert(tw_bitmap_test(dst, k));
        ck_assert(tw_bitmap_test(tmp, k));
      }
    }

    tw_bitmap_free(tmp);
    tw_bitmap_free(src);
    tw_bitmap_free(dst);
  }
}
Ejemplo n.º 27
0
END_TEST

START_TEST(test_tcpv4_inet)
{
    int server_root_socket, server_client_socket, client_socket;
    char buffer[BUFFERSIZE];
    char *msg;
    char ipbuffer[BUFFERSIZE];

    ck_assert_int_ge((server_root_socket = OS_Bindporttcp(PORT, NULL, 0)), 0);

    ck_assert_int_ge((client_socket = OS_ConnectTCP(PORT, IPV4, 0, NULL)) , 0);

    ck_assert_int_ge((server_client_socket = OS_AcceptTCP(server_root_socket, ipbuffer, BUFFERSIZE)), 0);

    ck_assert_str_eq(ipbuffer, IPV4);

    ck_assert_int_eq(OS_SendTCP(client_socket, SENDSTRING), 0);

    ck_assert_int_eq(OS_RecvTCPBuffer(server_client_socket, buffer, BUFFERSIZE), 0);

    ck_assert_str_eq(buffer, SENDSTRING);

    ck_assert_int_eq(OS_SendTCPbySize(server_client_socket, 5, SENDSTRING), 0);

    ck_assert_ptr_ne((msg = OS_RecvTCP(client_socket, BUFFERSIZE)), NULL);

    ck_assert_str_eq(msg, "Hello"); /* only 5 bytes send */

    free(msg);

    OS_CloseSocket(client_socket);
    OS_CloseSocket(server_client_socket);
    OS_CloseSocket(server_root_socket);
}
Ejemplo n.º 28
0
END_TEST

START_TEST(test_udpv6)
{
    int server_socket, client_socket;
    char buffer[BUFFERSIZE];
    char *msg;

    ck_assert_int_ge((server_socket = OS_Bindportudp(PORT, IPV6, 1)), 0);

    ck_assert_int_ge((client_socket = OS_ConnectUDP(PORT, IPV6, 1, NULL)) , 0);

    //TODO: ck_assert_int_eq(OS_SendUDP(client_socket, SENDSTRING), 0);
    ck_assert_int_eq(OS_SendUDPbySize(client_socket, strlen(SENDSTRING), SENDSTRING), 0);

    //TODO: not null-terminated
    ck_assert_int_eq(OS_RecvConnUDP(server_socket, buffer, BUFFERSIZE), strlen(SENDSTRING));

    ck_assert_str_eq(buffer, SENDSTRING);

    ck_assert_int_eq(OS_SendUDPbySize(client_socket, 5, SENDSTRING), 0);

    ck_assert_ptr_ne((msg = OS_RecvUDP(server_socket, BUFFERSIZE)), NULL);

    ck_assert_str_eq(msg, "Hello"); /* only 5 bytes send */

    free(msg);

    OS_CloseSocket(client_socket);
    OS_CloseSocket(server_socket);
}
Ejemplo n.º 29
0
END_TEST

START_TEST (test_api) 
{
    freesasa_parameters p = freesasa_default_parameters;
    p.shrake_rupley_n_points = 20; // so the loop below will be fast

    freesasa_set_verbosity(FREESASA_V_SILENT);
    for (int i = 1; i < 50; ++i) {
        p.alg = FREESASA_SHRAKE_RUPLEY;
        set_fail_freq(i);
        ck_assert_int_eq(freesasa_calc(&coord, r, &p), NULL);
        p.alg = FREESASA_LEE_RICHARDS; 
        set_fail_freq(i);
        ck_assert_int_eq(freesasa_calc(&coord, r, &p), NULL);
    }

    FILE *file = fopen(DATADIR "1ubq.pdb","r");
    set_fail_freq(10000);
    freesasa_structure *s=freesasa_structure_from_pdb(file, NULL, 0);
    ck_assert_ptr_ne(s,NULL);
    for (int i = 1; i < 256; i *= 2) { //try to spread it out without doing too many calculations
        set_fail_freq(i);
        ck_assert_ptr_eq(freesasa_calc_structure(s, NULL), NULL);
        set_fail_freq(i);
        ck_assert_ptr_eq(freesasa_structure_get_chains(s, "A"), NULL);
    }
    set_fail_freq(1);
    freesasa_structure_free(s);
    fclose(file);
    freesasa_set_verbosity(FREESASA_V_NORMAL);
}
Ejemplo n.º 30
0
END_TEST


START_TEST(test_basic_simple)
{
  GpuArray a;
  GpuArray b;
  GpuArray c;

  GpuElemwise *ge;

  static const uint32_t data1[3] = {1, 2, 3};
  static const uint32_t data2[3] = {4, 5, 6};
  uint32_t data3[3] = {0};

  size_t dims[2];

  gpuelemwise_arg args[3] = {{0}};
  void *rargs[3];

  dims[0] = 1;
  dims[1] = 3;

  ga_assert_ok(GpuArray_empty(&a, ctx, GA_UINT, 2, dims, GA_C_ORDER));
  ga_assert_ok(GpuArray_write(&a, data1, sizeof(data1)));

  ga_assert_ok(GpuArray_empty(&b, ctx, GA_UINT, 2, dims, GA_F_ORDER));
  ga_assert_ok(GpuArray_write(&b, data2, sizeof(data2)));

  ga_assert_ok(GpuArray_empty(&c, ctx, GA_UINT, 2, dims, GA_C_ORDER));

  args[0].name = "a";
  args[0].typecode = GA_UINT;
  args[0].flags = GE_READ;

  args[1].name = "b";
  args[1].typecode = GA_UINT;
  args[1].flags = GE_READ;

  args[2].name = "c";
  args[2].typecode = GA_UINT;
  args[2].flags = GE_WRITE;

  ge = GpuElemwise_new(ctx, "", "c = a + b", 3, args, 2, 0);

  ck_assert_ptr_ne(ge, NULL);

  rargs[0] = &a;
  rargs[1] = &b;
  rargs[2] = &c;

  ga_assert_ok(GpuElemwise_call(ge, rargs, GE_NOCOLLAPSE));

  ga_assert_ok(GpuArray_read(data3, sizeof(data3), &c));

  ck_assert_int_eq(data3[0], 5);
  ck_assert_int_eq(data3[1], 7);
  ck_assert_int_eq(data3[2], 9);
}