static void
test_secure_channel_listen_start_listen_failed() {
  setup();

  int listen_fd = 1;

  listener_info.listen_fd = -1;

  expect_value( mock_socket, domain, PF_INET );
  expect_value( mock_socket, type, SOCK_STREAM );
  expect_value( mock_socket, protocol, 0 );
  will_return( mock_socket, listen_fd );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, SOL_SOCKET, 1 );
  expect_value_count( mock_setsockopt, optname, SO_REUSEADDR, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, 0, 1 );

  expect_value_count( mock_setsockopt, sockfd, listen_fd, 1 );
  expect_value_count( mock_setsockopt, level, IPPROTO_TCP, 1 );
  expect_value_count( mock_setsockopt, optname, TCP_NODELAY, 1 );
  expect_not_value_count( mock_setsockopt, optval, NULL, 1 );
  expect_value_count( mock_setsockopt, optlen, sizeof( int ), 1 );
  will_return_count( mock_setsockopt, 0, 1 );

  expect_value( mock_bind, sockfd, listen_fd );
  expect_not_value( mock_bind, addr_in, NULL );
  expect_value( mock_bind, addrlen, sizeof( struct sockaddr_in ) );
  expect_value( mock_bind, sin_family32, AF_INET );
  expect_value( mock_bind, sin_port32, ( uint32_t ) htons( OFP_TCP_PORT ) );
  expect_value( mock_bind, addr_in->sin_addr.s_addr, htonl( INADDR_ANY ) );
  will_return( mock_bind, 0 );

  expect_value( mock_listen, sockfd, listen_fd );
  expect_value( mock_listen, backlog, 128 );
  will_return( mock_listen, -1 );

  expect_value( mock_close, fd, listen_fd );
  will_return_void( mock_close );

  assert_false( secure_channel_listen_start( &listener_info ) );
  assert_true( listener_info.listen_fd == -1 );

  teardown();
}
Example #2
0
void test_user_groups_retrieves_users_groups(CuTest *tc)
{
    char **groups;
    setup();

    groups = user_get_groups("bob", "first");
    CuAssertPtrNotNull(tc, groups);
    CuAssertStrEquals(tc, "admin", groups[0]);
    CuAssertStrEquals(tc, "user", groups[1]);

    /* This assertion ensures that groups come from a single
     * animal.
     */
    CuAssertPtrEquals(tc, NULL, groups[2]);

    teardown();
}
static void testMakeReferenceGreedily(CuTest *testCase) {
    for (int64_t i = 0; i < 100; i++) {
        setup();
        double totalScore;
        time_t startTime = time(NULL);
        bool fast = 1; //st_random() > 0.5;
        stList *reference = makeReferenceGreedily(stubs, chains, zMatrix,
                nodeNumber, &totalScore, fast);
        checkIsValidReference(testCase, reference, totalScore);
        time_t totalTime = time(NULL) - startTime;
        char *cA = stString_print("Greedy (fast:%" PRIi64 "), %" PRIi64 " nodes, it took %" PRIi64 " seconds, score: %f\n", fast, nodeNumber, totalTime, totalScore);
        st_logInfo(cA);
        logReference(reference, nodeNumber, zMatrix, totalScore, cA);
        free(cA);
        teardown();
    }
}
BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
    : Plasma::AbstractRunner(parent, args)
{
    Q_UNUSED(args)
    setObjectName( QLatin1String("Bookmarks" ));
    m_icon = KIcon("bookmarks");
    m_bookmarkManager = KBookmarkManager::userBookmarksManager();
    m_browser = whichBrowser();
    addSyntax(Plasma::RunnerSyntax(":q:", i18n("Finds web browser bookmarks matching :q:.")));
    setDefaultSyntax(Plasma::RunnerSyntax(i18nc("list of all web browser bookmarks", "bookmarks"),
                                   i18n("List all web browser bookmarks")));

    connect(this, SIGNAL(prepare()), this, SLOT(prep()));
    connect(this, SIGNAL(teardown()), this, SLOT(down()));

    reloadConfiguration();
}
Example #5
0
static void
test_init_and_finalize_match_table_successed() {
  setup();

  assert_true( match_table_head.exact_table == NULL );
  assert_true( match_table_head.wildcard_table == NULL );

  init_match_table();
  assert_true( match_table_head.exact_table != NULL );
  assert_true( match_table_head.wildcard_table == NULL );

  finalize_match_table();
  assert_true( match_table_head.exact_table == NULL );
  assert_true( match_table_head.wildcard_table == NULL );

  teardown();
}
Example #6
0
void UnityTestRunner(unityfunction* setup,
        unityfunction* testBody,
        unityfunction* teardown,
        const char * printableName,
        const char * group,
        const char * name,
        const char * file, int line)
{
    if (testSelected(name) && groupSelected(group))
    {
        Unity.CurrentTestFailed = 0;
        Unity.TestFile = file;
        Unity.CurrentTestName = printableName;
        Unity.CurrentTestLineNumber = line;
        if (!UnityFixture.Verbose)
            UNITY_OUTPUT_CHAR('.');
        else
            UnityPrint(printableName);

        Unity.NumberOfTests++;
        UnityMalloc_StartTest();
        UnityPointer_Init();

        runTestCase();
        if (TEST_PROTECT())
        {
            setup();
            testBody();
        }
        if (TEST_PROTECT())
        {
            teardown();
        }
        if (TEST_PROTECT())
        {
            UnityPointer_UndoAllSets();
            if (!Unity.CurrentTestFailed)
                UnityMalloc_EndTest();
            UnityConcludeFixtureTest();
        }
        else
        {
            //aborting - jwg - di i need these for the other TEST_PROTECTS?
        }
    }
}
Example #7
0
/**
 * test_scrollbars_hide_when_zooming_out:
 *
 * The objective of this test is to verify that the scrollbars aren't
 * shown if the view is zoomed out so that it exactly fits inside its
 * allocation.
 *
 * For example if the image width is 100, zoom 1.0 and allocation
 * width 55, then the scrollbars are shown, 100 * 1.0 > 55. If the
 * image is then zoomed out to 0.5 zoom, the scrollbars shouldn't be
 * shown, 100 * 0.5 < 55.
 **/
static void
test_scrollbars_hide_when_zooming_out ()
{
    printf ("test_scrollbars_hide_when_zooming_out\n");
    setup ();

    GtkAllocation alloc = {0, 0, 105, 105};
    
    gtk_widget_set_allocation (GTK_WIDGET (scroll_win), &alloc);
    fake_realize (GTK_WIDGET (scroll_win));

    gtk_widget_set_allocation (GTK_WIDGET (view), &alloc);
    fake_realize (GTK_WIDGET (view));

    gtk_image_view_set_pixbuf (view, pixbuf, TRUE);
    // 105 > 100, so no scrollbars
    assert (!gtk_widget_get_visible (scroll_win->hscroll));
    assert (!gtk_widget_get_visible (scroll_win->vscroll));

    gtk_image_view_zoom_in (view);
    // 105 < 100 * 1.5, so show scrollbars. Due to the scrollbars, the
    // views allocation changes! The scrollbars are roughly 15 pixels
    // in width and height. In real code, the zoom in action would
    // automatically cause the allocation to be recalculated, but I
    // don't know how to simulate that.
    gtk_widget_get_allocation (GTK_WIDGET (view), &alloc);
    alloc.width -= 15;
    alloc.height -= 15;
    gtk_widget_set_allocation (GTK_WIDGET (view), &alloc);
    assert (gtk_widget_get_visible (scroll_win->hscroll));
    assert (gtk_widget_get_visible (scroll_win->vscroll));

    gtk_image_view_zoom_out (view);
    // 105 > 100, so no scrollbars. Same here as above, the zoom out
    // should cause the view to be resized.

    gtk_widget_get_allocation (GTK_WIDGET (view), &alloc);
    alloc.width += 15;
    alloc.height += 15;
    gtk_widget_set_allocation (GTK_WIDGET (view), &alloc);
    
    assert (!gtk_widget_get_visible (scroll_win->hscroll));
    assert (!gtk_widget_get_visible (scroll_win->vscroll));

    teardown();
}
Example #8
0
/* perform read command */
int doread(char *name, int rnum, int rnd){
  WT_CURSOR *c;
  WT_ITEM key, value;
  int i, err;
  char buf[RECBUFSIZ];
  if(showprgr)
    printf("<Read Test of Row Store>\n  name=%s  rnum=%d\n\n", name, rnum);
  /* open a database */
  if(setup(name, NULL, NULL, NULL, &c) != 0){
    fprintf(stderr, "open failed\n");
    return 1;
  }
  err = FALSE;
  key.data = value.data = buf;
  key.size = value.size = 8;
  /* loop for each record */
  for(i = 1; i <= rnum; i++){
    /* store a record */
    sprintf(buf, "%08d", rnd ? myrand() % rnum + 1 : i);
    c->set_key(c, &key);
    if(c->search(c) != 0){
      fprintf(stderr, "search failed\n");
      err = TRUE;
      break;
    }
    /* Include the cost of getting the value. */
    c->get_value(c, &value);
    /* print progression */
    if(showprgr && rnum > 250 && i % (rnum / 250) == 0){
      putchar('.');
      fflush(stdout);
      if(i == rnum || i % (rnum / 10) == 0){
        printf(" (%08d)\n", i);
        fflush(stdout);
      }
    }
  }
  /* close the database */
  if(teardown() != 0) {
    fprintf(stderr, "close failed\n");
    return 1;
  }
  if(showprgr && !err)
    printf("ok\n\n");
  return err ? 1 : 0;
}
Example #9
0
static void
test_secure_channel_fd_isset_succeeded() {
  setup();

  fd_set read_set, write_set;

  expect_value( mock_secure_channel_accept, listener_info, &listener_info );
  will_return_void( mock_secure_channel_accept );

  listener_info.listen_fd = 1;
  FD_ZERO( &read_set );
  FD_ZERO( &write_set );
  FD_SET( listener_info.listen_fd, &read_set );
  secure_channel_fd_isset( &read_set, &write_set );

  teardown();
}
Example #10
0
static void
test_register_dl_type_filter() {
  setup();

  uint32_t dl_type32 = 1;
  uint32_t priority32 = 2;

  expect_not_value( mock_insert_match_entry, ofp_match, NULL );
  expect_value( mock_insert_match_entry, priority32, priority32 );
  expect_string( mock_insert_match_entry, service_name, "service_name" );
  expect_string( mock_insert_match_entry, entry_name, "entry_name" );
  will_return_void( mock_insert_match_entry );

  register_dl_type_filter( ( uint16_t ) dl_type32, ( uint16_t ) priority32, "service_name", "entry_name" );

  teardown();
}
Example #11
0
static void testSetRecord(CuTest *testCase) {
    /*
     * Tests 'setting' records (where you don't know if it's an update or an insert).
     */
    setup();
    int64_t i = 100;
    stKVDatabase_setRecord(database, 1, &i, sizeof(int64_t));
    int64_t *j = stKVDatabase_getRecord(database, 1);
    CuAssertTrue(testCase, i == *j);
    free(j);
    i = 110;
    stKVDatabase_setRecord(database, 1, &i, sizeof(int64_t));
    j = stKVDatabase_getRecord(database, 1);
    CuAssertTrue(testCase, i == *j);
    free(j);
    teardown();
}
Example #12
0
/*
 *	Main function
 */
int main( int argc, char** argv )
{
	// Set up tests
	setup();

	// Register suit setup and clean-up functions
	suite_setup(my_suite_setup);
	suite_teardown(my_suite_teardown);

	// Run all test suits
	run_tests(all_test_suits);	

	// Clean up tests
	teardown();

	return 0;
}
Example #13
0
static int
runtest_(const char *testname, int (*testfunc)(void), void (*setup)(void),
         void (*teardown)(void))
{
    int nf;
    if (setup)
        setup();
    nf = testfunc();
    if (teardown)
        teardown();
    printf("%c", nf>0 ? 'F':'.');
    fflush(stdout);
    if (nf > 0)
        sprintf(failed, "%s ** F: %s failed: %s!\n", failed, testname,
                result_msg);
    return nf;
}
Example #14
0
bool MessageWindow::onPush(const ::CEGUI::EventArgs& e)
{
   if (_state == S_INIT) { return true; }

   int i;
   {
      const ::CEGUI::WindowEventArgs& we = static_cast< const ::CEGUI::WindowEventArgs& >(e);
      for (i=0; i<_buttons.size(); ++i) {
         if (_buttons[i].pButton == we.window) { break; }
      }
      if (i == _buttons.size()) { return true; }
   }

   _pushed = i;
   teardown();
   return true;
}
Example #15
0
static void
test_insert_and_delete_of_wildcard_any_lldp_ipv4_entry() {
  setup();

  struct ofp_match match, lookup_match;
  match_entry *match_entry;

  init_match_table();

  intsert_any_match_entry();
  intsert_lldp_match_entry();
  intsert_ipv4_match_entry();

  delete_ipv4_match_entry();
  delete_any_match_entry();

  memset( &lookup_match, 0, sizeof( struct ofp_match ) );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  memset( &lookup_match, 0, sizeof( struct ofp_match ) );
  lookup_match.dl_type = ETH_ETHTYPE_LLDP;

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  set_lldp_match_entry( &match );
  assert_memory_equal( &match_entry->ofp_match, &match, sizeof( struct ofp_match ) );
  assert_true( match_entry->priority == LLDP_MATCH_PRIORITY );
  assert_string_equal( match_entry->service_name, LLDP_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, LLDP_MATCH_ENTRY_NAME );

  delete_lldp_match_entry();

  memset( &lookup_match, 0, sizeof( struct ofp_match ) );
  lookup_match.dl_type = ETH_ETHTYPE_LLDP;

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  finalize_match_table();

  teardown();
}
Example #16
0
static int one_sided_test(void)
{
  extoll_t ex;
  struct extoll_params params;
  int ret_val = 0;

  size_t size_B = (1 << 10);
  size_t count = size_B/sizeof(uint32_t);

  printf("Size of buffer is %lu  B\n", size_B);

  //extoll_server_connect allocates memory

  //Initialize the buffer to all 0s and then set the buffer length
  memset(&params, 0, sizeof(struct extoll_params));
  //Use bytes for the buffer length here
  params.buf_len  = size_B;

  if (!(ex = setup(&params)))
    return -1;

  uint32_t* buf_ptr = (uint32_t*)ex->rma_conn.buf;
  //Remember to memset using bytes
  memset(buf_ptr, 1234, size_B);

  //Wait for the client to connect and perform read/write operations
  //This is mainly used to keep the allocation active for this test since
  //we aren't doing reads/writes here.
  extoll_notification(ex);
  
  uint32_t i ;
  for (i = 0; i < count; i++)
    if (buf_ptr[i] != 1234)
    {
      printf("buf_ptr[%d] mismatch=%x\n", i, buf_ptr[i]);
      ret_val = -1;
    }
  
  if(teardown(ex) != 0)
    return -1;

  /*Return 0 on success*/
  return ret_val;

}
Example #17
0
int main(int argc, char *argv[])
{
  setup();
  mu_run_test(test_TATXStat_name);
  mu_run_test(test_TATXStat_count);
  mu_run_test(test_TATXStat_totalElapsedTime);
  mu_run_test(test_TATXStat_errorCount);
  mu_run_test(test_TATXStat_errorCode);
  mu_run_test(test_TATXStat_errorMessage);
  mu_run_test(test_TATXStat_avgElapsedTime);
  mu_run_test(test_TATXStat_tps);
  mu_run_test(test_TATXStat_deepCopy);
  mu_run_test(test_TATXStat_minus);
  mu_run_test(test_TATXStat_plus);
  teardown();
  mu_show_failures();
  return mu_nfail != 0;
}
Example #18
0
int main()
{
    const UnitTest tests[] =
        {
            unit_test(test_newentry),
            unit_test(test_update),
            unit_test(test_reverse_missing),
            unit_test(test_reverse_conflict),
            unit_test(test_reverse_missing_forward),
            unit_test(test_remove),
        };

    int ret = run_tests(tests);

    teardown();

    return ret;
}
Example #19
0
int execute(int argc, char *argv[], char *name, int (*f)(void)) {
    int status; 
    if (f==NULL) {
        log_error("no test function to execute");       
        return TEST_ERROR;
    }
    log_info("TEST %s start", name);
    error_flag = 0;
    setup(argc, argv);
    status = f();
    if (status || error_flag){
        log_info("TEST %s: FAILED", name);
    } else {
        log_info("TEST %s: PASSED", name);
    }
    teardown();
    return status;
}
Example #20
0
static void
test_lookup_of_wildcard_lldp_entry_failed() {
  setup();

  struct ofp_match lookup_match;
  match_entry *match_entry;

  init_match_table();

  memset( &lookup_match, 0, sizeof( struct ofp_match ) );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  finalize_match_table();

  teardown();
}
Example #21
0
static void
test_lookup_of_exact_alice_entry_failed() {
  setup();

  struct ofp_match lookup_match;
  match_entry *match_entry;

  init_match_table();

  set_alice_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry == NULL );

  finalize_match_table();

  teardown();
}
void pa__done(pa_module*m) {
    struct userdata *u;

    pa_assert(m);

    if (!(u = m->userdata))
        return;

    teardown(u);

    if (u->memblockq)
        pa_memblockq_free(u->memblockq);

    if (u->asyncmsgq)
        pa_asyncmsgq_unref(u->asyncmsgq);

    pa_xfree(u);
}
Example #23
0
static void test_short_buffer(int in, int nonblock)
{
	char buffer[1024]; /* events are typically 32 bytes */
	int fd = setup(in, nonblock);

	generate_event(fd);
	generate_event(fd);

	wait_for_event(fd);

	alarm(3);

	igt_assert_eq(read(fd, buffer, 4), 0);
	igt_assert(read(fd, buffer, 40) > 0);
	igt_assert(read(fd, buffer, 40) > 0);

	teardown(fd);
}
Example #24
0
static void run_switcher ( ModeMode mode )
{
    pfd = setup ();
    if ( pfd < 0 ) {
        return;
    }
    // Otherwise check if requested mode is enabled.
    for ( unsigned int i = 0; i < num_modi; i++ ) {
        if ( !mode_init ( modi[i] ) ) {
            rofi_view_error_dialog ( ERROR_MSG ( "Failed to initialize all the modi." ), ERROR_MSG_MARKUP );
            teardown ( pfd );
            return;
        }
    }
    char *input = g_strdup ( config.filter );
    __run_switcher_internal ( mode, input );
    g_free ( input );
}
Example #25
0
static void
test_secure_channel_fd_set_succeeded() {
  setup();

  fd_set read_set, write_set;

  listener_info.listen_fd = 1;
  FD_ZERO( &read_set );
  FD_ZERO( &write_set );
  secure_channel_fd_set( &read_set, &write_set );

  assert_true( FD_ISSET( listener_info.listen_fd, &read_set ) );
  FD_CLR( listener_info.listen_fd, &read_set );
  assert_true( FD_ISZERO( &read_set ) );
  assert_true( FD_ISZERO( &write_set ) );

  teardown();
}
Example #26
0
int main(int argc, char **argv)
{
    const char *args[] = {"--nodes", "5", NULL};

    if (getenv("LIBCOUCHBASE_VERBOSE_TESTS") == NULL) {
        freopen("/dev/null", "w", stdout);
    }

    setup((char **)args);

    reproduce_double_free_error();

    teardown();

    (void)argc;
    (void)argv;
    return EXIT_SUCCESS;
}
Example #27
0
static void
test_insert_and_lookup_of_exact_all_entry() {
  setup();

  struct ofp_match lookup_match;
  match_entry *match_entry;

  init_match_table();

  intsert_alice_match_entry();
  intsert_bob_match_entry();
  intsert_carol_match_entry();

  set_alice_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, ALICE_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, ALICE_MATCH_ENTRY_NAME );

  set_bob_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, BOB_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, BOB_MATCH_ENTRY_NAME );

  set_carol_match_entry( &lookup_match );

  match_entry = lookup_match_entry( &lookup_match );
  assert_true( match_entry != NULL );

  assert_memory_equal( &match_entry->ofp_match, &lookup_match, sizeof( struct ofp_match ) );
  assert_string_equal( match_entry->service_name, CAROL_MATCH_SERVICE_NAME );
  assert_string_equal( match_entry->entry_name, CAROL_MATCH_ENTRY_NAME );

  finalize_match_table();

  teardown();
}
Example #28
0
int main(int argc, char** argv) {
   setup();

   testFormat();
   testMount();
   testUnmount();
   testMountAndUnmount();

   wrapTest(testFileCreationAndDeletion);
   wrapTest(testBulkWriteAndRead);
   wrapTest(testSeek);
   wrapTest(testIncrementalWriteAndRead);
   wrapTest(testDirCreationAndDeletion);
   wrapTest(testNestedDirCreationAndDeletion);

   teardown();

   return 0;
}
Example #29
0
int main()
{
  int i,n;
  scanf("%i", &n);

  for (i=0; i<n; i++) {
    setup();
    scanf("%s%s", str_a, str_b);
    str_reverse(str_a);
    str_reverse(str_b);

    sprintf(sum, "%i", atoi(str_a) + atoi(str_b));
    str_reverse(sum);

    printf("%i\n", atoi(sum));
    teardown();
  }
  return 0;
}
Example #30
0
int main (int argc, char *argv[]) {
  int has_failures = 0;

  if (setup() != 0) {
    fprintf(stderr, "(%s:%d): %s",
            __FILE__, __LINE__, "setup failed.");
    exit(EXIT_FAILURE);
  }

  has_failures += test_dbfr_open();
  has_failures += test_dbfr_init();
  has_failures += test_dbfr_getline_1();
  has_failures += test_dbfr_getline_2();

  teardown();
  if (has_failures)
    return 1;
  return 0;
}