Esempio n. 1
0
static void signature_verify_file(void)
{
	GError *error = NULL;
	GBytes *sig = read_file("test/openssl-ca/manifest-r1.sig", NULL);
	GBytes *isig = read_file("test/random.dat", NULL);

	g_assert_nonnull(sig);
	g_assert_nonnull(isig);

	// Test valid manifest
	g_assert_true(cms_verify_file("test/openssl-ca/manifest", sig, 0, &error));
	g_assert_null(error);

	// Test non-existing file
	g_assert_false(cms_verify_file("path/to/nonexisting/file", sig, 0, &error));
	g_assert_nonnull(error);

	g_clear_error(&error);

	// Test valid manifest against invalid signature
	g_assert_false(cms_verify_file("test/openssl-ca/manifest", isig, 0, &error));
	g_assert_nonnull(error);

	g_clear_error(&error);

	g_bytes_unref(sig);
	g_bytes_unref(isig);
}
Esempio n. 2
0
static void test_simple(void)
{
    g_remove("/tmp/test.key");
    /* we made sure that file is removed */
    g_assert_false(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));

    MConnCrypt *cr = m_conn_crypt_new_for_key_path("/tmp/test.key");
    g_assert_nonnull(cr);
    g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));

    gchar *pubkey1 = m_conn_crypt_get_public_key_pem(cr);

    m_conn_crypt_unref(cr);
    /* file should still exit */
    g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));

    cr = m_conn_crypt_new_for_key_path("/tmp/test.key");
    /* key should have been loaded */
    g_assert_nonnull(cr);
    g_assert_true(g_file_test("/tmp/test.key", G_FILE_TEST_EXISTS));

    gchar *pubkey2 = m_conn_crypt_get_public_key_pem(cr);

    m_conn_crypt_unref(cr);

    g_assert_cmpstr(pubkey1, ==, pubkey2);
}
Esempio n. 3
0
ATTR_PRINTF_FORMAT (2,3) gchar *
_lp_event_to_string (lp_Event *event, const gchar *fmt, ...)
{
  va_list args;
  gchar *suffix = NULL;
  gchar *str;
  gint n;

  va_start (args, fmt);
  n = g_vasprintf (&suffix, fmt, args);
  g_assert_nonnull (suffix);
  g_assert (n >= 0);
  va_end (args);

  str = g_strdup_printf ("\
%s at %p\n\
  source: %s at %p\n\
  mask: 0x%x\n\
%s\
",                       G_OBJECT_TYPE_NAME (event),
                         G_TYPE_CHECK_INSTANCE_CAST (event,
                                                     G_OBJECT_TYPE (event),
                                                     gpointer),
                         LP_IS_SCENE (event->priv->source) ? "lp_Scene"
                         : LP_IS_MEDIA (event->priv->source) ? "lp_Media"
                         : "unknown",
                         event->priv->source,
                         (guint) event->priv->mask,
                         suffix);
  g_assert_nonnull (str);
  g_free (suffix);

  return str;
}
Esempio n. 4
0
static int _CtSgwGetNumOfNodes(const char *service_name, const char *object_path)
{
	GDBusNodeInfo *node_info;
	GVariant *result;
	const gchar *xml_data;
	GError *error = NULL;
	int n = 0;

	result = g_dbus_connection_call_sync (sgw_dbus_service_context->connection,
											 service_name,
											 object_path,
											 "org.freedesktop.DBus.Introspectable",
											 "Introspect",
											 NULL,
											 G_VARIANT_TYPE("(s)"),
											 G_DBUS_CALL_FLAGS_NONE,
											 -1,
											 NULL,
											 &error);
	g_assert_nonnull(result);
	g_variant_get (result, "(&s)", &xml_data);
	
	node_info = g_dbus_node_info_new_for_xml (xml_data, &error);
	g_assert_no_error (error);
	g_assert_nonnull(node_info);
		
	for (n = 0; node_info->nodes != NULL && node_info->nodes[n] != NULL; n++) {
		;//do nothing
	}

	g_variant_unref(result);
	g_dbus_node_info_unref (node_info);

	return n;
}
Esempio n. 5
0
static void
test_xmlnode_prefixes(void) {
	const char *xml_doc =
		"<iq type='get' xmlns='jabber:client' xmlns:ping='urn:xmpp:ping'>"
			"<ping:ping>"
				"<child1>"
					"<ping:child2></ping:child2>" /* xmlns='jabber:child' */
				"</child1>"
			"</ping:ping>"
		"</iq>";
	char *str;
	PurpleXmlNode *xml, *reparsed;

	xml = purple_xmlnode_from_str(xml_doc, -1);
	check_doc_structure(xml);

	/* Check that purple_xmlnode_from_str(purple_xmlnode_to_str(xml, NULL), -1) is idempotent. */
	str = purple_xmlnode_to_str(xml, NULL);
	g_assert_nonnull(str);
	reparsed = purple_xmlnode_from_str(str, -1);
	g_assert_nonnull(reparsed);
	check_doc_structure(reparsed);

	g_free(str);
	purple_xmlnode_free(xml);
	purple_xmlnode_free(reparsed);
}
void testHandleCreated(handleFixture *fixture, gconstpointer ignored) {
    (void)ignored;
    g_assert_nonnull(fixture->dnfContext);
    g_assert_nonnull(fixture->handle);
    g_assert_cmpint(fixture->handle->version, ==, 1);
    g_assert_cmpint(fixture->handle->mode, ==, PLUGIN_MODE_CONTEXT);
}
Esempio n. 7
0
File: dir.c Progetto: gflima/nclua
static int
l_dir_dir (lua_State *L)
{
  const char *path;
  GDir *gdir;
  GError *error;
  dir_t *dir;

  path = luaL_checkstring (L, 1);
  error = NULL;
  gdir = g_dir_open (path, 0, &error);
  if (unlikely (gdir == NULL))
    {
      g_assert_nonnull (error);
      lua_pushfstring (L, "%s", error->message);
      g_error_free (error);
      return lua_error (L);
    }

  dir = (dir_t *) lua_newuserdata (L, sizeof (*dir));
  g_assert_nonnull (dir);
  dir->gdir = gdir;

  lua_pushcclosure (L, l_dir_dir_it_closure, 1);
  return 1;
}
Esempio n. 8
0
static void init_virtio_dev(TestServer *s, uint32_t features_mask)
{
    uint32_t features;
    int i;

    s->bus = qpci_init_pc(global_qtest, NULL);
    g_assert_nonnull(s->bus);

    s->dev = qvirtio_pci_device_find(s->bus, VIRTIO_ID_NET);
    g_assert_nonnull(s->dev);

    qvirtio_pci_device_enable(s->dev);
    qvirtio_reset(&s->dev->vdev);
    qvirtio_set_acknowledge(&s->dev->vdev);
    qvirtio_set_driver(&s->dev->vdev);

    s->alloc = pc_alloc_init(global_qtest);

    for (i = 0; i < s->queues * 2; i++) {
        s->vq[i] = qvirtqueue_setup(&s->dev->vdev, s->alloc, i);
    }

    features = qvirtio_get_features(&s->dev->vdev);
    features = features & features_mask;
    qvirtio_set_features(&s->dev->vdev, features);

    qvirtio_set_driver_ok(&s->dev->vdev);
}
Esempio n. 9
0
gboolean r_umount_slot(RaucSlot *slot, GError **error) {
	GError *ierror = NULL;
	gboolean res = FALSE;

	g_assert_nonnull(slot);
	g_assert_nonnull(slot->mount_point);
	g_assert_true(slot->mount_internal);

	res = r_umount(slot->mount_point, &ierror);
	if (!res) {
		res = FALSE;
		g_propagate_prefixed_error(
				error,
				ierror,
				"failed to unmount slot: ");
		goto out;
	}

	g_rmdir(slot->mount_point);
	g_clear_pointer(&slot->mount_point, g_free);
	slot->mount_internal = FALSE;

out:
	return res;
}
Esempio n. 10
0
gboolean test_make_slot_user_writable(const gchar* path, const gchar* file) {
	gboolean res = FALSE;
	gchar *slotpath;
	gchar *mountpath;
	
	slotpath = g_build_filename(path, file, NULL);
	g_assert_nonnull(slotpath);

	mountpath = g_build_filename(path, "tmpmount", NULL);
	g_assert_nonnull(mountpath);

	if (!g_file_test(mountpath, G_FILE_TEST_IS_DIR)) {
		g_assert(test_mkdir_relative(path, "tmpmount", 0777) == 0);
	}

	test_mount(slotpath, mountpath);

	test_do_chmod(mountpath);

	r_umount(mountpath, NULL);

	res = TRUE;

	return res;
}
Esempio n. 11
0
static void
test_area_updated_anim (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    channel = g_io_channel_new_file (filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding(channel, NULL, NULL);
    /*create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect (loader, "area-prepared",
                      (GCallback) callback_area_prepared_anim, NULL);
    /* other callbacks will be registered inside callback_area_prepared_anim */

    /*read animation by portions of bytes */
#if 0
    while(loader_write_from_channel(loader, channel, 20) == 20);
#endif
    /* or read it at once */
    loader_write_from_channel (loader, channel, G_MAXSIZE);

    /* free resources */
    g_io_channel_unref (channel);
    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
Esempio n. 12
0
static void
test_area_updated_ico (gconstpointer data)
{
    const char *filename;
    GIOChannel *channel;
    GdkPixbufLoader *loader;

    filename = g_test_get_filename (G_TEST_DIST, data, NULL);

    /* create channel */
    channel = g_io_channel_new_file(filename, "r", NULL);
    g_assert_nonnull (channel);
    g_io_channel_set_encoding (channel, NULL, NULL);
    /* create loader */
    loader = gdk_pixbuf_loader_new ();
    g_assert_nonnull (loader);

    g_signal_connect(loader, "area-prepared",
                    (GCallback) callback_area_prepared, NULL);
    /* callbacks for "area-updated" and "closed" signals will be connected
     * in callback_area_prepared() */

    /* read image byte by byte */
    while (loader_write_from_channel(loader, channel, 1) == 1);
    /* or read full image at once */
#if 0
    loader_write_from_channel(loader, channel, G_MAXSIZE);
#endif

    /* free resources */
    g_io_channel_unref (channel);

    gdk_pixbuf_loader_close (loader, NULL);
    g_object_unref (loader);
}
Esempio n. 13
0
void test_portal_train_enters_from_portal(test_portal_context* test_ctx, const void* data) {
	#pragma unused(data)
	sem_world* world = &(test_ctx->game.world);

	sem_train_entry_context context;
	sem_coordinate_set(&(context.position), 0, 0);
	context.direction = SEM_EAST;
	context.cars = 2;

	sem_action action;
	action.time = 2000;
	action.game = &(test_ctx->game);
	action.context = &context;
	action.dynamically_allocated = false;

	sem_train_entry_action(world->actions, &action);

	g_assert_cmpuint(world->trains->tail_idx, ==, 1);
	sem_train* train = (sem_train*) world->trains->items[0];
	g_assert_true(train->state == MOVING);

	sem_action* move_action = sem_heap_remove_earliest(world->actions);
	g_assert_nonnull(move_action);
	g_assert_cmpuint(move_action->time, ==, 3000);
	g_assert_true(move_action->function(world->actions, move_action) == SEM_OK);
	g_assert_cmpuint(train->position->x, ==, 1);
	g_assert_cmpuint(train->position->y, ==, 0);
	
	g_assert_cmpuint(train->cars, ==, 2);

	move_action = sem_heap_remove_earliest(world->actions);
	g_assert_nonnull(move_action);
	g_assert_true(move_action->function(world->actions, move_action) == SEM_OK);
	g_assert_cmpuint(train->cars, ==, 2);
}
Esempio n. 14
0
static void signature_verify(void)
{
	GBytes *content = read_file("test/openssl-ca/manifest", NULL);
	GBytes *sig = read_file("test/openssl-ca/manifest-r1.sig", NULL);
	g_assert_nonnull(content);
	g_assert_nonnull(sig);
	g_assert_true(cms_verify(content, sig, NULL));
	g_bytes_unref(content);
	g_bytes_unref(sig);
}
Esempio n. 15
0
static void
_locator (gpointer u, struct sqlx_name_s *n, GString *file_name)
{
	(void) u;
	g_assert_nonnull (n);
	g_assert_nonnull (file_name);
	g_assert_nonnull (n->ns);
	g_assert_nonnull (n->base);
	g_assert_nonnull (n->type);
	g_string_assign (file_name, ":memory:");
}
Esempio n. 16
0
static void test_cookie_get_from_snapd__nofile()
{
	struct sc_error *err = NULL;
	char *cookie;

	set_fake_cookie_dir();

	cookie = sc_cookie_get_from_snapd("test-snap2", &err);
	g_assert_nonnull(err);
	g_assert_cmpstr(sc_error_domain(err), ==, SC_ERRNO_DOMAIN);
	g_assert_nonnull(strstr(sc_error_msg(err), "cannot open cookie file"));
	g_assert_null(cookie);
}
Esempio n. 17
0
int
main (int argc, char **argv)
{
	HC_TEST_INIT(argc,argv);
	ns = g_getenv ("OIO_NS");
	acct = g_getenv ("OIO_ACCOUNT");
	user = g_getenv ("OIO_USER");
	g_assert_nonnull (g_getenv ("OIO_NS"));
	g_assert_nonnull (g_getenv ("OIO_ACCOUNT"));
	g_assert_nonnull (g_getenv ("OIO_USER"));
	g_test_add_func("/sqlx/client/sds", test_sds);
	return g_test_run();
}
Esempio n. 18
0
static void
_cpml_method_from_segment(void)
{
    CpmlSegment segment;
    CpmlPrimitive primitive;

    g_assert_true(cpml_segment_from_cairo(&segment, (cairo_path_t *) adg_test_path()));

    cpml_primitive_from_segment(&primitive, &segment);
    g_assert_nonnull(primitive.segment);
    g_assert_nonnull(primitive.org);
    g_assert_nonnull(primitive.data);
}
/* Finds the big file in the deployment to figure out its checksum, so
 * it can then remove it from client's repository.
 */
static void
delete_big_file_object_from_client_repo (EtcData *data)
{
  const gchar *bigfile_path = eos_test_client_get_big_file_path ();
  const gchar *paths[] =
    {
      bigfile_path,
      NULL
    };
  g_autoptr(GFile) client_repo = NULL;
  OstreeLsFlags flags = OSTREE_LS_CHECKSUM;
  g_auto(CmdResult) listed = CMD_RESULT_CLEARED;
  g_autoptr(GError) error = NULL;
  g_autofree gchar *escaped_bigfile_path = NULL;
  g_autofree gchar *regex = NULL;
  g_autoptr(GRegex) gregex = NULL;
  gboolean matched;
  g_autoptr(GMatchInfo) match_info = NULL;
  g_autofree gchar *checksum = NULL;
  g_autofree gchar *object = NULL;

  g_assert_nonnull (data);
  g_assert_nonnull (data->client);

  client_repo = eos_test_client_get_repo (data->client);
  ostree_ls (client_repo,
             flags,
             default_ref,
             paths,
             &listed,
             &error);
  g_assert_no_error (error);
  g_assert_true (cmd_result_ensure_ok_verbose (&listed));

  escaped_bigfile_path = g_regex_escape_string (bigfile_path, -1);
  regex = g_strdup_printf ("\\s+([0-9a-zA-Z]{64})\\s+%s", escaped_bigfile_path);
  gregex = g_regex_new (regex,
                        /* compile flags: */ 0,
                        /* match flags: */ 0,
                        &error);
  g_assert_no_error (error);
  matched = g_regex_match (gregex,
                           listed.standard_output,
                           /* match flags: */ 0,
                           &match_info);
  g_assert_true (matched);
  checksum = g_match_info_fetch (match_info,
                                 /* match group: */ 1);
  object = g_strdup_printf ("%s.file", checksum);
  etc_delete_object (client_repo, object);
}
Esempio n. 20
0
static void char_ringbuf_test(void)
{
    QemuOpts *opts;
    Chardev *chr;
    CharBackend be;
    char *data;
    int ret;

    opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
                            1, &error_abort);
    qemu_opt_set(opts, "backend", "ringbuf", &error_abort);

    qemu_opt_set(opts, "size", "5", &error_abort);
    chr = qemu_chr_new_from_opts(opts, NULL);
    g_assert_null(chr);
    qemu_opts_del(opts);

    opts = qemu_opts_create(qemu_find_opts("chardev"), "ringbuf-label",
                            1, &error_abort);
    qemu_opt_set(opts, "backend", "ringbuf", &error_abort);
    qemu_opt_set(opts, "size", "2", &error_abort);
    chr = qemu_chr_new_from_opts(opts, &error_abort);
    g_assert_nonnull(chr);
    qemu_opts_del(opts);

    qemu_chr_fe_init(&be, chr, &error_abort);
    ret = qemu_chr_fe_write(&be, (void *)"buff", 4);
    g_assert_cmpint(ret, ==, 4);

    data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
    g_assert_cmpstr(data, ==, "ff");
    g_free(data);

    data = qmp_ringbuf_read("ringbuf-label", 4, false, 0, &error_abort);
    g_assert_cmpstr(data, ==, "");
    g_free(data);

    qemu_chr_fe_deinit(&be, true);

    /* check alias */
    opts = qemu_opts_create(qemu_find_opts("chardev"), "memory-label",
                            1, &error_abort);
    qemu_opt_set(opts, "backend", "memory", &error_abort);
    qemu_opt_set(opts, "size", "2", &error_abort);
    chr = qemu_chr_new_from_opts(opts, NULL);
    g_assert_nonnull(chr);
    object_unparent(OBJECT(chr));
    qemu_opts_del(opts);
}
Esempio n. 21
0
void test_portal_train_exits_into_portal(test_portal_context* test_ctx, const void* data) {
	#pragma unused(data)
	sem_world* world = &(test_ctx->game.world);

	sem_train* train = malloc(sizeof(sem_train));	
	sem_train_init(train);
	train->state = MOVING;
	train->direction = SEM_EAST;
	sem_world_add_train(world, train);

	sem_car* tail_car = malloc(sizeof(sem_car));
	sem_coordinate_set(&(tail_car->position), 1, 0);
	tail_car->track = sem_tile_at(world, 1, 0)->track;

	sem_car* head_car = malloc(sizeof(sem_car));
	sem_coordinate_set(&(head_car->position), 2, 0);
	head_car->track = sem_tile_at(world, 2, 0)->track;

	sem_train_add_car(train, head_car);
	sem_train_add_car(train, tail_car);

	sem_action action;
	action.time = 2000;
	action.game = &(test_ctx->game);
	action.context = train;
	action.function = sem_move_train_action;
	action.dynamically_allocated = false;

	g_assert_true(sem_move_train_action(world->actions, &action) == SEM_OK);

	sem_action* move_action = sem_heap_remove_earliest(world->actions);
	g_assert_nonnull(move_action);
	g_assert_true(move_action->function(world->actions, move_action) == SEM_OK);

	g_assert_cmpuint(train->cars, ==, 1);
	g_assert_cmpuint(train->position->x, ==, 3);
	g_assert_cmpuint(train->position->y, ==, 0);

	move_action = sem_heap_remove_earliest(world->actions);
	g_assert_nonnull(move_action);
	g_assert_true(move_action->function(world->actions, move_action) == SEM_OK);

	sem_action* train_exit_action = sem_heap_remove_earliest(world->actions);
	g_assert_nonnull(train_exit_action);
	train_exit_action->function(world->actions, move_action);

	g_assert_cmpuint(world->trains->tail_idx, ==, 0);
}
void
test_setup_thetvdb (void)
{
  GrlConfig *config;
  GrlRegistry *registry;
  GError *error = NULL;

  if (tmp_dir == NULL) {
    /* Only create tmp dir and set the XDG_DATA_HOME once */
    tmp_dir = g_build_filename (g_get_tmp_dir (), "test-thetvdb-XXXXXX", NULL);
    tmp_dir = g_mkdtemp (tmp_dir);
    g_assert_nonnull (tmp_dir);

    g_setenv ("XDG_DATA_HOME", tmp_dir, TRUE);
  }

  config = grl_config_new (THETVDB_ID, NULL);
  grl_config_set_api_key (config, "THETVDB_TEST_MOCK_API_KEY");

  registry = grl_registry_get_default ();
  grl_registry_add_config (registry, config, &error);
  g_assert_no_error (error);

  grl_registry_load_plugin_by_id (registry, THETVDB_ID, &error);
  g_assert_no_error (error);

  source = GRL_SOURCE (grl_registry_lookup_source (registry, THETVDB_ID));
  g_assert (source != NULL);

  g_assert (grl_source_supported_operations (source) & GRL_OP_RESOLVE);
}
Esempio n. 23
0
static void test_qga_sync_delimited(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    guint32 v, r = g_random_int();
    unsigned char c;
    QDict *ret;
    gchar *cmd;

    cmd = g_strdup_printf("%c{'execute': 'guest-sync-delimited',"
                          " 'arguments': {'id': %u } }", 0xff, r);
    qmp_fd_send(fixture->fd, cmd);
    g_free(cmd);

    v = read(fixture->fd, &c, 1);
    g_assert_cmpint(v, ==, 1);
    g_assert_cmpint(c, ==, 0xff);

    ret = qmp_fd_receive(fixture->fd);
    g_assert_nonnull(ret);
    qmp_assert_no_error(ret);

    v = qdict_get_int(ret, "return");
    g_assert_cmpint(r, ==, v);

    QDECREF(ret);
}
Esempio n. 24
0
static void test_qga_sync(gconstpointer fix)
{
    const TestFixture *fixture = fix;
    guint32 v, r = g_random_int();
    QDict *ret;

    /*
     * TODO guest-sync is inherently limited: we cannot distinguish
     * failure caused by reacting to garbage on the wire prior to this
     * command, from failure of this actual command. Clients are
     * supposed to be able to send a raw '\xff' byte to at least
     * re-synchronize the server's parser prior to this command, but
     * we are not in a position to test that here because (at least
     * for now) it causes the server to issue an error message about
     * invalid JSON. Testing of '\xff' handling is done in
     * guest-sync-delimited instead.
     */
    ret = qmp_fd(fixture->fd,
                 "{'execute': 'guest-sync', 'arguments': {'id': %u } }",
                 r);

    g_assert_nonnull(ret);
    qmp_assert_no_error(ret);

    v = qdict_get_int(ret, "return");
    g_assert_cmpint(r, ==, v);

    qobject_unref(ret);
}
Esempio n. 25
0
static GError*
location_from_chunk_id(const gchar *chunk_id, const gchar *ns_name,
		struct oio_lb_pool_s *pool, oio_location_t *location)
{
	g_assert_nonnull(location);
	GError *err = NULL;
	if (chunk_id == NULL || strlen(chunk_id) <= 0)
		return NEWERROR(CODE_INTERNAL_ERROR, "emtpy chunk id");

	gchar *netloc = NULL;
	oio_parse_chunk_url(chunk_id, NULL, &netloc, NULL);

	if (pool) {
		gchar *key = oio_make_service_key(ns_name, NAME_SRVTYPE_RAWX, netloc);
		struct oio_lb_item_s *item = oio_lb_pool__get_item(pool, key);
		g_free(key);
		if (item) {
			*location = item->location;
			g_free(item);
			goto out;
		}
	}

	addr_info_t ai = {{0}};
	if (!err && !grid_string_to_addrinfo(netloc, &ai))
		err = NEWERROR(CODE_INTERNAL_ERROR,
				"could not parse [%s] to addrinfo", netloc);
	if (!err)
		*location = location_from_addr_info(&ai);

out:
	g_free(netloc);
	return err;
}
Esempio n. 26
0
static void
test_parse_partial_str(StateWrapper *wrapper, gconstpointer user_data)
{
    guchar buffer[] = { 0x00, 0x0e, 0x00, 0x73, 0x6f, 0x6f, 0x73, 0x68, 0x69, 0x20 };
    wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer, sizeof(buffer));

    SooshiNode *node = g_new0(SooshiNode, 1);
    node->type = VAL_STR;

    // First run should return NULL and not remove any bytes from the byte array
    gulong byte_array_size = wrapper->state->buffer->len;
    sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value);
    
    g_assert_null(node->value);
    g_assert_cmpuint(byte_array_size, ==, wrapper->state->buffer->len);

    guchar buffer2[] = { 0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67 };
    wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer2, sizeof(buffer2));
    
    // Second run should now be able to succesfully parse the string
    sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value);

    g_assert_nonnull(node->value);
    g_assert_true(g_variant_is_of_type(node->value, G_VARIANT_TYPE_STRING));
    g_assert_cmpstr(g_variant_get_string(node->value, NULL), ==, "sooshi testing");

    guchar buffer3[16];
    gint length = sooshi_node_value_to_bytes(node, buffer3);
    g_assert_cmpint(length, ==, sizeof(buffer3));
    g_assert_cmpmem(buffer3, sizeof(buffer) - 1, buffer + 1, sizeof(buffer) - 1); 
    g_assert_cmpmem(buffer3 + sizeof(buffer) - 1, sizeof(buffer3) - (sizeof(buffer) - 1), buffer2, sizeof(buffer2)); 

    g_free(node);
}
Esempio n. 27
0
static void
test_parse_flt(StateWrapper *wrapper, gconstpointer user_data)
{
    float real_value = 12.3456789;
    guchar buffer[] = { 0x00,
        ((guchar*)&real_value)[0],
        ((guchar*)&real_value)[1],
        ((guchar*)&real_value)[2],
        ((guchar*)&real_value)[3],
    };
    wrapper->state->buffer = g_byte_array_append(wrapper->state->buffer, buffer, sizeof(buffer));

    SooshiNode *node = g_new0(SooshiNode, 1);
    node->type = VAL_FLT;

    sooshi_node_bytes_to_value(node, wrapper->state->buffer, &node->value);

    g_assert_nonnull(node->value);
    g_assert_true(g_variant_is_of_type(node->value, G_VARIANT_TYPE_DOUBLE));
    g_assert_cmpfloat(g_variant_get_double(node->value), ==, real_value);

    guchar buffer2[4];
    gint length = sooshi_node_value_to_bytes(node, buffer2);
    g_assert_cmpint(length, ==, sizeof(buffer2));
    g_assert_cmpmem(buffer2, length, buffer + 1, sizeof(buffer) - 1); 

    g_free(node);
}
Esempio n. 28
0
static void
test_strip_prefixes(void) {
	const char *xml_doc = "<message xmlns='jabber:client' from='[email protected]/resource' to='*****@*****.**' type='chat' id='purple'>"
		"<cha:active xmlns:cha='http://jabber.org/protocol/chatstates'/>"
		"<body>xvlc xvlc</body>"
		"<im:html xmlns:im='http://jabber.org/protocol/xhtml-im'>"
			"<xht:body xmlns:xht='http://www.w3.org/1999/xhtml'>"
				"<xht:p>xvlc <xht:span style='font-weight: bold;'>xvlc</xht:span></xht:p>"
			"</xht:body>"
		"</im:html>"
	"</message>";
	const char *out = "<message xmlns='jabber:client' from='[email protected]/resource' to='*****@*****.**' type='chat' id='purple'>"
		"<active xmlns:cha='http://jabber.org/protocol/chatstates' xmlns='http://jabber.org/protocol/chatstates'/>"
		"<body>xvlc xvlc</body>"
		"<html xmlns:im='http://jabber.org/protocol/xhtml-im' xmlns='http://jabber.org/protocol/xhtml-im'>"
			"<body xmlns:xht='http://www.w3.org/1999/xhtml' xmlns='http://www.w3.org/1999/xhtml'>"
				"<p>xvlc <span style='font-weight: bold;'>xvlc</span></p>"
			"</body>"
		"</html>"
	"</message>";
	char *str;
	PurpleXmlNode *xml;

	xml = purple_xmlnode_from_str(xml_doc, -1);
	g_assert_nonnull(xml);

	purple_xmlnode_strip_prefixes(xml);
	str = purple_xmlnode_to_str(xml, NULL);
	g_assert_cmpstr(out, ==, str);
	g_free(str);

	purple_xmlnode_free(xml);
}
Esempio n. 29
0
guint
conscience_srvtype_remove_expired(struct conscience_srvtype_s * srvtype,
    service_callback_f * callback, gpointer u)
{
	g_assert_nonnull (srvtype);

	guint count = 0U;

	time_t oldest = oio_ext_monotonic_seconds();
	if (oldest > srvtype->score_expiration)
		oldest -= srvtype->score_expiration;
	else
		oldest = 0;

	GHashTableIter iter;
	gpointer key, value;
	g_hash_table_iter_init(&iter, srvtype->services_ht);
	while (g_hash_table_iter_next(&iter, &key, &value)) {
		struct conscience_srv_s *pService = value;
		if (!pService->locked && pService->score.timestamp < oldest) {
			if (pService->score.value > 0) {
				if (callback)
					callback(pService, u);
				pService->score.value = 0;
				count++;
			}
		}
	}

	return count;
}
Esempio n. 30
0
static void
get_system_language (void)
{
  GwLanguage *language;
  GError *error;
  gboolean system_language_set;

  /* Set a random language if host system has none set */
  system_language_set = gw_get_system_language (NULL, NULL);

  /* Create the language */
  error = NULL;
  language = gw_language_new_sync (NULL, NULL, &error);

  if (!system_language_set)
    {
      g_assert_error (error, GW_LANGUAGE_ERROR, GW_LANGUAGE_ERROR_INVALID);
      g_assert_null (language);
    }
  else
    {
      g_message ("Language: %s", gw_language_get_language_code (language));

      g_assert_nonnull (language);
      g_assert_no_error (error);

      g_clear_object (&language);
    }

  g_clear_object (&language);
}