Exemple #1
0
/* This test imports an RTF file, exports it, and imports it again. The export
operation cannot fail, but if either import operation fails, the test fails. It
then compares the plaintext of the two GtkTextBuffers, and if they differ, the
test fails. Otherwise, the test succeeds.
Comparing the plaintext is for lack of a better way to compare the text buffers'
formatting. */
static void
rtf_write_pass_case(gconstpointer name)
{
    GError *error = NULL;
    GtkTextBuffer *buffer1 = gtk_text_buffer_new(NULL);
    GtkTextBuffer *buffer2 = gtk_text_buffer_new(NULL);
    gchar *filename = build_filename(name);
    
	if(!rtf_text_buffer_import(buffer1, filename, &error))
	    g_test_message("Import error message: %s", error->message);
	g_free(filename);
	g_assert(error == NULL);
	gchar *string = rtf_text_buffer_export_to_string(buffer1);
	if(!rtf_text_buffer_import_from_string(buffer2, string, &error))
	    g_test_message("Export error message: %s", error->message);
	g_assert(error == NULL);
	    
	GtkTextIter start, end;
	gtk_text_buffer_get_bounds(buffer1, &start, &end);
	gchar *text1 = gtk_text_buffer_get_slice(buffer1, &start, &end, TRUE);
	gtk_text_buffer_get_bounds(buffer2, &start, &end);
	gchar *text2 = gtk_text_buffer_get_slice(buffer2, &start, &end, TRUE);
	g_assert_cmpstr(text1, ==, text2);
	
	g_free(text1);
	g_free(text2);
	g_object_unref(buffer1);
	g_object_unref(buffer2);
	g_free(string);
}
Exemple #2
0
static bool ufd_version_check(void)
{
    struct uffdio_api api_struct;
    uint64_t ioctl_mask;

    int ufd = ufd = syscall(__NR_userfaultfd, O_CLOEXEC);

    if (ufd == -1) {
        g_test_message("Skipping test: userfaultfd not available");
        return false;
    }

    api_struct.api = UFFD_API;
    api_struct.features = 0;
    if (ioctl(ufd, UFFDIO_API, &api_struct)) {
        g_test_message("Skipping test: UFFDIO_API failed");
        return false;
    }

    ioctl_mask = (__u64)1 << _UFFDIO_REGISTER |
                 (__u64)1 << _UFFDIO_UNREGISTER;
    if ((api_struct.ioctls & ioctl_mask) != ioctl_mask) {
        g_test_message("Skipping test: Missing userfault feature");
        return false;
    }

    return true;
}
Exemple #3
0
static const char *init_hugepagefs(const char *path)
{
    struct statfs fs;
    int ret;

    if (access(path, R_OK | W_OK | X_OK)) {
        g_test_message("access on path (%s): %s\n", path, strerror(errno));
        return NULL;
    }

    do {
        ret = statfs(path, &fs);
    } while (ret != 0 && errno == EINTR);

    if (ret != 0) {
        g_test_message("statfs on path (%s): %s\n", path, strerror(errno));
        return NULL;
    }

    if (fs.f_type != HUGETLBFS_MAGIC) {
        g_test_message("Warning: path not on HugeTLBFS: %s\n", path);
        return NULL;
    }

    return path;
}
Exemple #4
0
GRAPHENE_TEST_UNIT_END

GRAPHENE_TEST_UNIT_BEGIN (ray_closest_point_to_point)
{
  graphene_point3d_t tmp = GRAPHENE_POINT3D_INIT (0.f, 0.f, 50.f);
  graphene_point3d_t check = GRAPHENE_POINT3D_INIT (1.f, 1.f, 50.f);
  graphene_point3d_t res;
  graphene_ray_t r;

  graphene_ray_init (&r, &one3, graphene_vec3_z_axis ());

  if (g_test_verbose ())
    g_test_message ("Behind the ray...");
  graphene_ray_get_closest_point_to_point (&r, &zero3, &res);
  g_assert_true (graphene_point3d_near (&res, &one3, 0.00001f));

  if (g_test_verbose ())
    g_test_message ("Front of the ray...");
  graphene_ray_get_closest_point_to_point (&r, &tmp, &res);
  g_assert_true (graphene_point3d_near (&res, &check, 0.00001f));

  if (g_test_verbose ())
    g_test_message ("On the ray...");
  graphene_ray_get_closest_point_to_point (&r, &one3, &res);
  g_assert_true (graphene_point3d_near (&res, &one3, 0.00001f));
}
static void
guile_main(void *closure, int argc, char ** argv)
{
    GNCModule foo;
    gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
    gchar *logdomain = "gnc.module";
    guint loglevel = G_LOG_LEVEL_WARNING;
    TestErrorStruct check = { loglevel, logdomain, msg };
    g_log_set_handler (logdomain, loglevel,
                       (GLogFunc)test_checked_handler, &check);

    g_test_message("  test-load-c.c: testing module load/unload from C ... ");

    gnc_module_system_init();

    foo = gnc_module_load("gnucash/foo", 0);

    if (!foo)
    {
        g_test_message("  Failed to load foo\n");
        exit(-1);
    }

    if (!gnc_module_unload(foo))
    {
        g_test_message("  Failed to unload foo\n");
        exit(-1);
    }
    g_test_message(" successful.\n");

    exit(0);
}
static void notify_load_status_cb(WebKitWebView* view, GParamSpec* pspec, GMainLoop* loop)
{
    WebKitLoadStatus status = webkit_web_view_get_load_status (view);
    WebKitWebFrame* frame = webkit_web_view_get_main_frame(view);
    WebKitWebDataSource* dataSource = webkit_web_frame_get_data_source(frame);

    if (status == WEBKIT_LOAD_COMMITTED) {
        g_assert(webkit_web_data_source_is_loading(dataSource));
        return;
    }
    else if (status != WEBKIT_LOAD_FINISHED)
        return;

    /* Test get_request */
    g_test_message("Testing webkit_web_data_source_get_request");
    WebKitNetworkRequest* request = webkit_web_data_source_get_request(dataSource);
    g_assert_cmpstr(webkit_network_request_get_uri(request), ==, "http://www.webkit.org/");

    /* Test get_main_resource */
    g_test_message("Testing webkit_web_data_source_get_main_resource");
    WebKitWebResource* resource = webkit_web_data_source_get_main_resource(dataSource);
    g_assert_cmpstr("text/html", ==, webkit_web_resource_get_mime_type(resource));
    g_assert_cmpstr("http://www.webkit.org/", ==, webkit_web_resource_get_uri(resource));

    /* Test get_data. We just test if data has certain size for the mean time */
    g_test_message("Testing webkit_web_data_source_get_data has certain size");
    GString* data = webkit_web_data_source_get_data(dataSource);
    g_assert(data->len > 100);

    /* FIXME: Add test for get_encoding */

    g_main_loop_quit(loop);
}
Exemple #7
0
GRAPHENE_TEST_UNIT_END

GRAPHENE_TEST_UNIT_BEGIN (ray_get_position_at)
{
  graphene_ray_t r;
  graphene_point3d_t tmp;

  graphene_ray_init (&r, &one3, graphene_vec3_z_axis ());

  if (g_test_verbose ())
    g_test_message ("On the ray's origin...");
  graphene_ray_get_position_at (&r, 0.f, &tmp);
  g_assert_true (graphene_point3d_equal (&tmp, &one3));

  if (g_test_verbose ())
    g_test_message ("Behind the ray...");
  graphene_ray_get_position_at (&r, -1.f, &tmp);
  graphene_assert_fuzzy_equals (tmp.x, 1.f, 0.0001);
  graphene_assert_fuzzy_equals (tmp.y, 1.f, 0.0001);
  graphene_assert_fuzzy_equals (tmp.z, 0.f, 0.0001);

  if (g_test_verbose ())
    g_test_message ("On the ray...");
  graphene_ray_get_position_at (&r, 1.f, &tmp);
  graphene_assert_fuzzy_equals (tmp.x, 1.f, 0.0001);
  graphene_assert_fuzzy_equals (tmp.y, 1.f, 0.0001);
  graphene_assert_fuzzy_equals (tmp.z, 2.f, 0.0001);
}
Exemple #8
0
static void
test_qof_object_compliance( Fixture *fixture, gconstpointer pData )
{
    g_assert( qof_object_register( fixture->qofobject ) );

    g_test_message( "Test when neither create nor foreach set" );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when only create set" );
    fixture->qofobject->create = mock_object_create;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when only foreach set" );
    fixture->qofobject->create = NULL;
    fixture->qofobject->foreach = mock_object_foreach;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == FALSE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == FALSE );

    g_test_message( "Test when both set" );
    fixture->qofobject->create = mock_object_create;
    fixture->qofobject->foreach = mock_object_foreach;
    g_assert( qof_object_compliance( fixture->qofobject->e_type, FALSE ) == TRUE );
    g_assert( qof_object_compliance( fixture->qofobject->e_type, TRUE ) == TRUE );
}
AtspiAccessible * get_root_obj (const char *file_name)
{
  int i;
  AtspiAccessible *obj = NULL;

  run_app (file_name);

  /* sleep is needed to wait for fored test application*/
  sleep (1);

  obj = atspi_get_desktop (0);
  gint child_count = atspi_accessible_get_child_count (obj, NULL);
  if (child_count < 1) {
    g_test_message ("Fail, test application not found\n");
    g_test_fail ();
    kill (child_pid, SIGTERM);
    return NULL;
  }

  for (i=0; i<child_count; i++) {
    AtspiAccessible *child = atspi_accessible_get_child_at_index (obj,i, NULL);
    if (!strcmp (atspi_accessible_get_name (child, NULL), "root_object"))
      return child;
  }
  g_test_message ("test object not found\n");
  g_test_fail ();

  kill (child_pid, SIGTERM);
  return NULL;
}
Exemple #10
0
static void
test_qof_object_new_instance( Fixture *fixture, gconstpointer pData )
{
    QofBook *book = NULL;
    QofInstance *inst = NULL;

    book = qof_book_new();
    g_assert( book );

    g_test_message( "Test null check" );
    g_assert( qof_object_new_instance( NULL, book ) == NULL );

    g_test_message( "Test non existing object type" );
    g_assert( qof_object_new_instance( "non existing type", book ) == NULL );

    g_test_message( "Test with registered object type and create not set" );
    g_assert( qof_object_register( fixture->qofobject ) );
    g_assert( qof_object_new_instance( fixture->qofobject->e_type, book ) == NULL );

    g_test_message( "Test with registered object type and create set" );
    object_create_struct.is_called = FALSE;
    object_create_struct.book = book;
    object_create_struct.inst = NULL;
    fixture->qofobject->create = mock_object_create;
    inst = qof_object_new_instance( fixture->qofobject->e_type, book );
    g_assert( inst );
    g_assert( object_create_struct.is_called == TRUE );
    g_assert( object_create_struct.inst == inst );

    g_object_unref( inst );
    qof_book_destroy( book );
}
Exemple #11
0
static void
test_qof_object_is_dirty( Fixture *fixture, gconstpointer pData )
{
    QofBook *book = NULL;
    gint32 list_length;

    g_test_message( "Test null check returns false" );
    g_assert( qof_object_is_dirty( NULL ) == FALSE );

    g_test_message( "Test with no objects" );
    book = qof_book_new();
    g_assert( book );
    object_dirty_struct.call_count = 0;
    g_assert( qof_object_is_dirty( book ) == FALSE );
    g_assert_cmpint( object_dirty_struct.call_count, == , 0 );

    list_length = generate_and_register_objects( 1, MOCK_OBJECT_DIRTY );

    g_test_message( "Test with registered objects and suppose all collections are clean" );
    object_dirty_struct.objects = get_object_modules();
    object_dirty_struct.result = FALSE;
    g_assert( qof_object_is_dirty( book ) == FALSE );
    g_assert_cmpint( object_dirty_struct.call_count, == , list_length );

    g_test_message( "Test with registered objects and suppose first collection is dirty" );
    object_dirty_struct.objects = get_object_modules();
    object_dirty_struct.result = TRUE;
    object_dirty_struct.call_count = 0;
    g_assert( qof_object_is_dirty( book ) == TRUE );
    g_assert_cmpint( object_dirty_struct.call_count, == , 1 ); /* should break on first */

    qof_book_destroy( book );
}
Exemple #12
0
static void
test_qof_object_book_end( Fixture *fixture, gconstpointer pData )
{
    QofBook *book = NULL, *book2 = NULL;
    gint32 list_length;

    g_test_message( "Test book with no objects" );
    book = qof_book_new();
    g_assert( book );
    object_book_begin_struct.call_count = 0;
    g_assert_cmpint( 1, == , g_list_length( get_book_list() ) );
    g_assert_cmpint( g_list_index( get_book_list(), (gconstpointer) book), != , -1 );
    qof_book_destroy( book ); /* calls object_book_end */
    g_assert_cmpint( object_book_begin_struct.call_count, == , 0 );
    g_assert_cmpint( 0, == , g_list_length( get_book_list() ) );

    list_length = generate_and_register_objects( 1, MOCK_OBJECT_BOOK_END );

    g_test_message( "Test book end with random objects registered and book end set up" );
    book2 = qof_book_new();
    g_assert( book2 );
    object_book_begin_struct.book = book2;
    g_assert_cmpint( 1, == , g_list_length( get_book_list() ) );
    g_assert_cmpint( g_list_index( get_book_list(), (gconstpointer) book2 ), != , -1 );
    qof_book_destroy( book2 ); /* calls object_book_end */
    g_assert_cmpint( object_book_begin_struct.call_count, == , list_length );
    g_assert_cmpint( 0, == , g_list_length( get_book_list() ) );
}
Exemple #13
0
static void check_time(int wiggle)
{
    struct tm start, date[4], end;
    struct tm *datep;
    time_t ts;

    /*
     * This check assumes a few things.  First, we cannot guarantee that we get
     * a consistent reading from the wall clock because we may hit an edge of
     * the clock while reading.  To work around this, we read four clock readings
     * such that at least two of them should match.  We need to assume that one
     * reading is corrupt so we need four readings to ensure that we have at
     * least two consecutive identical readings
     *
     * It's also possible that we'll cross an edge reading the host clock so
     * simply check to make sure that the clock reading is within the period of
     * when we expect it to be.
     */

    ts = time(NULL);
    gmtime_r(&ts, &start);

    cmos_get_date_time(&date[0]);
    cmos_get_date_time(&date[1]);
    cmos_get_date_time(&date[2]);
    cmos_get_date_time(&date[3]);

    ts = time(NULL);
    gmtime_r(&ts, &end);

    if (tm_cmp(&date[0], &date[1]) == 0) {
        datep = &date[0];
    } else if (tm_cmp(&date[1], &date[2]) == 0) {
        datep = &date[1];
    } else if (tm_cmp(&date[2], &date[3]) == 0) {
        datep = &date[2];
    } else {
        g_assert_not_reached();
    }

    if (!(tm_cmp(&start, datep) <= 0 && tm_cmp(datep, &end) <= 0)) {
        long t, s;

        start.tm_isdst = datep->tm_isdst;

        t = (long)mktime(datep);
        s = (long)mktime(&start);
        if (t < s) {
            g_test_message("RTC is %ld second(s) behind wall-clock\n", (s - t));
        } else {
            g_test_message("RTC is %ld second(s) ahead of wall-clock\n", (t - s));
        }

        g_assert_cmpint(ABS(t - s), <=, wiggle);
    }
Exemple #14
0
static void
render_test (gconstpointer user_data)
{
	const char *filename = user_data;
	char *basename;
	LsmDomDocument *document;
	LsmDomView *view;
	LsmBox viewport;
	unsigned int width, height;
	cairo_t *cairo;
	cairo_surface_t *surface;

	basename = g_path_get_basename (filename);

	document = lsm_dom_document_new_from_path (filename, NULL);
	g_assert (LSM_IS_DOM_DOCUMENT (document));

	view = lsm_dom_document_create_view (document);
	g_assert (LSM_IS_DOM_VIEW (view));

	viewport.x = 0.0;
	viewport.y = 0.0;
	viewport.width = 480.0;
	viewport.height = 360.0;

	lsm_dom_view_set_resolution (view, 96);
	lsm_dom_view_set_viewport_pixels (view, &viewport);

	lsm_dom_view_get_size_pixels (LSM_DOM_VIEW (view), &width, &height, NULL);

	surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height);
	cairo = cairo_create (surface);
	cairo_surface_destroy (surface);

	if (cairo_status (cairo) == CAIRO_STATUS_SUCCESS) {
		lsm_dom_view_render (LSM_DOM_VIEW (view), cairo, 1, 1);

		if (cairo_status (cairo) != CAIRO_STATUS_SUCCESS) {
			g_test_message ("cairo_status = %s", cairo_status_to_string (cairo_status (cairo)));
			if (!g_key_file_get_boolean (suite_options, basename, "ignore-cairo-status", NULL)) {
				g_test_message ("incorrect cairo status");
				g_test_fail ();
			}
		}
	}

	cairo_destroy (cairo);

	g_object_unref (view);
	g_object_unref (document);

	g_free (basename);
}
Exemple #15
0
static void
test_qof_object_get_type_label( Fixture *fixture, gconstpointer pData )
{
    g_assert( qof_object_get_type_label( NULL ) == NULL );

    g_test_message( "Test with non existing object" );
    g_assert( qof_object_get_type_label( "anytype" ) == NULL );

    g_test_message( "Test with existing registered object" );
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert_cmpstr( qof_object_get_type_label( "my type object" ), == , "object desc" );
}
Exemple #16
0
static void
test_qof_object_lookup( Fixture *fixture, gconstpointer pData )
{
    g_test_message( "Test null check" );
    g_assert( qof_object_lookup( NULL ) == NULL );

    g_test_message( "Test existing object lookup" );
    g_assert( qof_object_register( fixture->qofobject ) == TRUE );
    g_assert( qof_object_lookup( "my type object" ) == fixture->qofobject );

    g_test_message( "Test non existing object lookup" );
    g_assert( qof_object_lookup( "anytype" ) == NULL );
}
Exemple #17
0
static void
test_entry_basics ( Fixture *fixture, gconstpointer pData )
{
    time64 ts1 = gnc_time(NULL), ts2;
    const char *desc = "Test description with éà unicode chars";
    const char *action = "Test action with éà unicode chars";
    const char *note = "Test note with éà unicode chars";
    gnc_numeric quantity = {500000, 100};
    gboolean is_cn = FALSE;

    GncEntry *entry = gncEntryCreate(fixture->book);
    g_assert(entry);

    g_test_message( "Test basic setters/getters" );
    g_test_message( "  Date" );
    gncEntrySetDate (entry, ts1);
    ts2 = gncEntryGetDate (entry);
    g_assert(ts2 == ts1);
    g_test_message( "  DateEntered" );
    gncEntrySetDateEntered (entry, ts1);
    ts2 = gncEntryGetDateEntered (entry);
    g_assert(ts2 == ts1);
    g_test_message( "  Description" );
    gncEntrySetDescription (entry, desc);
    g_assert(g_strcmp0 (gncEntryGetDescription (entry), desc) == 0);
    g_test_message( "  Action" );
    gncEntrySetAction (entry, action);
    g_assert(g_strcmp0 (gncEntryGetAction (entry), action) == 0);
    g_test_message( "  Notes" );
    gncEntrySetNotes (entry, note);
    g_assert(g_strcmp0 (gncEntryGetNotes (entry), note) == 0);
    g_test_message( "  Quantity" );
    gncEntrySetQuantity (entry, quantity);
    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
    g_test_message( "  DocQuantity (with is_cn = FALSE)" );
    gncEntrySetDocQuantity (entry, quantity, is_cn);
    g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), quantity));
    g_test_message( "  DocQuantity (with is_cn = TRUE)");
    is_cn = TRUE;
    gncEntrySetDocQuantity (entry, quantity, is_cn);
    g_assert(gnc_numeric_eq (gncEntryGetDocQuantity (entry, is_cn), quantity));
    g_assert(gnc_numeric_eq (gncEntryGetQuantity (entry), gnc_numeric_neg (quantity)));
    g_test_message( "  InvAccount" );
    gncEntrySetInvAccount (entry, fixture->account);
    g_assert(gncEntryGetInvAccount (entry) == fixture->account);

}
Exemple #18
0
static inline void out_reg(IVState *s, enum Reg reg, unsigned v)
{
    const char *name = reg2str(reg);

    g_test_message("%x -> *%s\n", v, name);
    qpci_io_writel(s->dev, s->reg_bar, reg, v);
}
Exemple #19
0
/**
 * test_symbol_flyweight:
 * @fn test_symbol_unicode
 * Tests whether compilerkit_symbol_new in CompilerKitSymbol struct allocates new space only for unique symbols.
 * @pre None
 * @param None
 * @return void
 */
void test_symbol_flyweight (void)
{
    CompilerKitSymbol *symbol1, *symbol2, *symbol3;
    
    g_test_message ("Testing Symbol unicode");
    g_test_timer_start ();
    
    /** @todo Test here  */
    symbol1 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));
    symbol2 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('b'));
    symbol3 = COMPILERKIT_SYMBOL (compilerkit_symbol_new('a'));

    /* Symbol b is distinct from Symbol a */
    g_assert (symbol2 != symbol3);
    g_assert (symbol2 != symbol1);

    /* The pointer to Symbol('a') should equal the pointer to Symbol('a').
       This of course, would make Ayn Rand proud ;-) */
    g_assert (symbol1 == symbol3);

    g_object_unref(symbol1);
    g_object_unref(symbol2);
    g_object_unref(symbol3);
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Exemple #20
0
/**
 * test_visitor_register_identity:
 * @fn test_visitor_register_identity
 * Tests whether compilerkit_visitor_register_identity function works as intended.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_register_identity (void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor *visitor;

    g_test_message ("Testing visitor register identity");
    g_test_timer_start ();

    symbol    = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor   = compilerkit_visitor_new();

    // Register the identity function (it returns whatever GObject* gets as a parameter during the visit)
    compilerkit_visitor_register_identity (visitor, COMPILERKIT_TYPE_EMPTY_SET);

    // Since we didn't register the symbol, the visitor should return NULL
    g_assert (compilerkit_visitor_visit (visitor, symbol) == NULL);

    // The visitor should produce symbol here, since we registered the identity function for the symbol class.
    g_assert (compilerkit_visitor_visit (visitor, empty_set) == empty_set);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
/**
 * test_alternation_vlist_new:
 * @fn test_alternation_vlist_new
 * Tests method compilerkit_alternation_vlist_new in CompilerKitAlternation struct.
 * @pre None
 * @param None
 * @return void
 */
void test_alternation_vlist_new (void)
{
	GObject* alt;
	GObject* one;
	GObject* two;
	GObject* three;
	
    g_test_message ("Testing Alternation vlist new");
    g_test_timer_start ();
	
	one = compilerkit_symbol_new('a');
	two = compilerkit_symbol_new('b');
	three = compilerkit_symbol_new('c');
	alt = compilerkit_alternation_vlist_new(one, two, three, NULL);
   
    g_assert (COMPILERKIT_IS_ALTERNATION(alt));
	g_assert (one != two);
	g_assert (two != three);
	g_assert (one != three);
	g_assert (one != alt);
	g_assert (two != alt);
	g_assert (three != alt);
	g_assert (three == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(alt)));
	g_assert (one == compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt)))));
	g_assert (two == compilerkit_alternation_get_right(COMPILERKIT_ALTERNATION(compilerkit_alternation_get_left(COMPILERKIT_ALTERNATION(alt)))));

	g_object_unref (alt); // This will unref one, two and three as well
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Exemple #22
0
/**
 * test_visitor_null_visit:
 * @fn test_visitor_null_visit
 * Tests whether compilerkit_visitor_visit produces appropriate results in the CompilerKitVisitor struct.
 * @pre None
 * @param None
 * @return void
 */
void test_visitor_null_visit(void)
{
    GObject *symbol;
    GObject *empty_set;
    CompilerKitVisitor* visitor;

    g_test_message ("Testing visitor null visits");
    g_test_timer_start ();

    symbol = compilerkit_symbol_new ('a');
    empty_set = compilerkit_empty_set_get_instance ();
    visitor = check_symbol();

    // Assert that visitor produces the correct result
    g_assert(compilerkit_visitor_visit(visitor, symbol) == symbol);

    // NULL objects will produce NULL
    g_assert(compilerkit_visitor_visit(visitor, NULL) == NULL);

    // Nothing registered for empty set, so return NULL
    g_assert(compilerkit_visitor_visit(visitor, empty_set) == NULL);

    // Decrease the reference count for objects to free them.
    g_object_unref (symbol);
    g_object_unref (empty_set);
    g_object_unref (visitor);

    // This test shouldn't take too long to run
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
}
Exemple #23
0
int main(int argc, char **argv)
{
    const char *arch = qtest_get_arch();
    char *cmdline;
    int ret;

    /* Check architecture */
    if (strcmp(arch, "i386") && strcmp(arch, "x86_64")) {
        g_test_message("Skipping test for non-x86\n");
        return 0;
    }

    open_socket();

    /* Run the tests */
    g_test_init(&argc, &argv, NULL);

    cmdline = g_strdup_printf(
          " -chardev socket,id=ipmi0,host=localhost,port=%d,reconnect=10"
          " -device ipmi-bmc-extern,chardev=ipmi0,id=bmc0"
          " -device isa-ipmi-bt,bmc=bmc0", emu_port);
    qtest_start(cmdline);
    qtest_irq_intercept_in(global_qtest, "ioapic");
    qtest_add_func("/ipmi/extern/connect", test_connect);
    qtest_add_func("/ipmi/extern/bt_base", test_bt_base);
    qtest_add_func("/ipmi/extern/bt_enable_irq", test_enable_irq);
    qtest_add_func("/ipmi/extern/bt_base_irq", test_bt_base);
    ret = g_test_run();
    qtest_quit(global_qtest);

    return ret;
}
Exemple #24
0
GRAPHENE_TEST_UNIT_END

GRAPHENE_TEST_UNIT_BEGIN (frustum_matrix_contains_point)
{
#if defined(GRAPHENE_USE_GCC)
# if GLIB_CHECK_VERSION (2, 38, 0)
  g_test_skip ("Disabled when using GCC vectors");
# else
  if (g_test_verbose ())
    g_test_message ("Disabled when using GCC vectors");
# endif
#else
  graphene_matrix_t m;
  graphene_frustum_t f;
  graphene_point3d_t p;

  graphene_matrix_init_frustum (&m, -1.f, 1.f, -1.f, 1.f, 1.f, 100.f);
  graphene_frustum_init_from_matrix (&f, &m);

  g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, 0.f)));
  g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, -50.f)));
  g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 0.f, 0.f, -1.001f)));
  g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, -1.f, -1.f, -1.001f)));
  g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, -1.1f, -1.1f, -1.001f)));
  g_assert_true (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 1.f, 1.f, -1.001f)));
  g_assert_false (graphene_frustum_contains_point (&f, graphene_point3d_init (&p, 1.1f, 1.1f, -1.001f)));
#endif
}
/* This helper function will run the parse step on the given data
 * with the parser as configured by the calling test function.
 * This allows the same code to be used with different csv test strings
 * and parser option combinations.
 */
static void
test_gnc_csv_parse_helper (GncCsvParseData *parse_data, gconstpointer pData)
{
    parse_test_data *test_data = (parse_test_data *) pData;
    GError *the_error = NULL;
    int resultcode = 0;
    int i = 0;

    while (test_data[i].csv_line)
    {
        int j;
        parse_test_data cur_line = test_data[i];

        g_test_message("Using string %s\n", cur_line.csv_line);
        g_free (parse_data->file_str.begin);
        parse_data->file_str.begin = g_strdup (cur_line.csv_line);
        parse_data->file_str.end = parse_data->file_str.begin + strlen (parse_data->file_str.begin);
        resultcode = gnc_csv_parse (parse_data, TRUE, &the_error);
        g_assert (resultcode == 0);
        for (j=0; j < cur_line.num_fields; j++)
        {
            g_assert (g_strcmp0 ((char*)((GPtrArray*)(parse_data->orig_lines->pdata[0]))->pdata[j],
                     (cur_line.fields[j])) == 0);
        }

        i++;
    }
}
static void
guile_main(void *closure, int argc, char ** argv)
{
    GNCModule foo;
    gchar *msg = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
    gchar *logdomain = "gnc.module";
    guint loglevel = G_LOG_LEVEL_WARNING;
    TestErrorStruct check = { loglevel, logdomain, msg };
    g_log_set_handler (logdomain, loglevel,
                       (GLogFunc)test_checked_handler, &check);
    g_test_message("  test-agedver.c:  asking for an old but supported interface ...");

    gnc_module_system_init();

    foo = gnc_module_load("gnucash/agedver", 5);

    if (foo)
    {
        printf("  ok\n");
        exit(0);
    }
    else
    {
        printf(" failed\n");
        exit(-1);
    }
}
Exemple #27
0
gboolean chk_skip(const gchar *test)
{
  const gchar *e = g_getenv("TEST_SKIP");
  gboolean r = FALSE;

  if (e == NULL || strlen(e) == 0)
    return (FALSE);
  {
    gchar **s = g_strsplit(e, ",", 0);
    gint i = -1;

    while (s != NULL && s[++i] != NULL)
      {
        if (match(test, s[i]) == TRUE)
          {
            g_test_message("SKIP: Remove '%s' from TEST_SKIP to enable",
                           test);
            r = TRUE;
            break;
          }
      }
    g_strfreev(s);
    s = NULL;
  }
  return (r);
}
Exemple #28
0
static void
gpdb_fixture_setup (GamePositionDbFixture *fixture,
                    gconstpointer          test_data)
{
  gchar *source = g_strdup("db/gpdb-ffo.txt");

  GamePositionDb               *db;
  GamePositionDbSyntaxErrorLog *syntax_error_log;
  FILE                         *fp;
  GError                       *error;

  /* Loads the game position database. */
  fp = fopen(source, "r");
  if (!fp) {
    g_test_message("Unable to open database test file \"%s\" for reading.\n", source);
    g_test_fail();
  }
  g_assert(fp);
  db = gpdb_new(g_strdup("FFOTEST database"));
  syntax_error_log = NULL;
  error = NULL;
  gpdb_load(fp, source, db, &syntax_error_log, &error);
  fclose(fp);
  g_free(source);

  /* Removes the tmp file, frees the resources. */
  g_free(error);
  if (syntax_error_log)
    gpdb_syntax_error_log_free(syntax_error_log);

  fixture->db = db;
  g_assert (fixture->db != NULL);
}
Exemple #29
0
static void
guile_main(void *closure, int argc, char ** argv)
{
    GNCModule foo;
    gchar *msg1 = "Module '../../../libgnucash/gnc-module/test/misc-mods/.libs/libgncmod_futuremodsys.so' requires newer module system\n";
    gchar *msg2 = "Could not locate module gnucash/incompatdep interface v.0";
    gchar *logdomain = "gnc.module";
    guint loglevel = G_LOG_LEVEL_WARNING;
    TestErrorStruct check1 = { loglevel, logdomain, msg1 };
    TestErrorStruct check2 = { loglevel, logdomain, msg2 };
    test_add_error (&check1);
    test_add_error (&check2);
    g_log_set_handler (logdomain, loglevel,
                       (GLogFunc)test_list_handler, NULL);

    g_test_message("  test-incompatdep.c:  loading a module with bad deps ...\n");

    gnc_module_system_init();

    foo = gnc_module_load("gnucash/incompatdep", 0);

    if (!foo)
    {
        printf("  ok\n");
        exit(0);
    }
    else
    {
        printf("  oops! loaded incompatible module\n");
        exit(-1);
    }
}
Exemple #30
0
/**
 * test_FSM_state:
 * @fn test_FSM_state
 * Tests `compilerkit_FSM_*_state` in CompilerKitFSM struct.
 * @pre None
 * @param None
 * @return void
 */
void test_FSM_states (void)
{
    CompilerKitFSM *fsm;
    g_test_message ("Testing FSM state");
    g_test_timer_start ();

    fsm = compilerkit_FSM_new ("zero");
    compilerkit_FSM_add_state (fsm, "one");
    compilerkit_FSM_add_state (fsm, "two");
    compilerkit_FSM_add_state (fsm, "three");
    
    g_assert (compilerkit_FSM_has_state (fsm, "zero"));
    g_assert (compilerkit_FSM_has_state (fsm, "one"));
    g_assert (compilerkit_FSM_has_state (fsm, "two"));
    g_assert (compilerkit_FSM_has_state (fsm, "three"));
    g_assert (!compilerkit_FSM_has_state (fsm, "four"));
    g_assert (!compilerkit_FSM_has_state (fsm, NULL));
    
    compilerkit_FSM_add_transition (fsm, "zero", "five", '5');
    compilerkit_FSM_add_accepting_state (fsm, "six");
    g_assert (compilerkit_FSM_has_state (fsm, "five"));
    g_assert (compilerkit_FSM_has_state (fsm, "six"));
    
    g_assert_cmpfloat(g_test_timer_elapsed (), <=, 1);
    g_object_unref (fsm);
}