void make_sure_ok(string s) {
    // s = s + "~";
    suffix_array sa1(s);
    naive_suffix_array sa2(s);

    // for (int i = 0; i < size(s); i++) {
    //     cout << s.substr(sa1.idx[i]) << endl;
    // }

    // cout << endl;
    // for (int i = 0; i < size(s); i++) {
    //     cout << s.substr(sa2.idx[i]) << endl;
    // }

    // cout << endl;

    for (int i = 0; i < size(s); i++) {

        assert_equal(sa1.idx[i], sa2.idx[i]);

        if (sa1.idx[i] != sa2.idx[i])
        {
            cout << s << endl;
        }
    }
}
int
test() {

    std::string s2 = "yabadabadoo";
    SuffixArray sa2(s2);
    print_ranks(s2, sa2);
    print_suffix_array(s2, sa2);

    vpii_t slcp;
    sa2.lcp_across_sets(4, slcp);
    for (size_t i = 0; i < slcp.size(); ++i) {
        printf("slcp[%d] = (%d, %d)\n", i, slcp[i].INDEX, slcp[i].LENGTH);
    }

    print_pairwise_lcp(s2, sa2);
    // return 0;

    SuffixArray sa1("banana");
    print_ranks("banana", sa1);

    SuffixArray sa3("mississippi");
    print_ranks("mississippi", sa3);

    std::string s4 = "Regular expressions, or just regexes, are at the core of Perl's text processing, and certainly are one of the features that made Perl so popular. All Perl programmers pass through a stage where they try to program everything as regexes, and when that's not challenging enough, everything as a single regex. Perl's regexes have many more features than I can, or want, to present here, so I include those advanced features I find most useful and expect other Perl programmers to know about without referring to perlre, the documentation page for regexes.";
    SuffixArray sa4(s4);
    print_ranks(s4, sa4);
    print_suffix_array(s4, sa4);

    cout<<endl;
    print_pairwise_lcp(s4, sa4);

    return 0;
}
Exemple #3
0
void test5(){
 	SharedArry<int> sa(new int[10]);
	SharedArry<int> sa1(sa);
	sa[0] = 10;
	SharedArry<int> sa2(new int[10]);
	SharedArry<int> sa3(sa2);
	sa2 = sa;
}
Exemple #4
0
	// ============================================================================
	// Address Test
	//
	void runAddressTest() 
	{
		TraceL << "Starting" << endl;		
		
		Address sa1("192.168.1.100", 100);
		assert(sa1.host() == "192.168.1.100");
		assert(sa1.port() == 100);

		Address sa2("192.168.1.100", "100");
		assert(sa2.host() == "192.168.1.100");
		assert(sa2.port() == 100);

		Address sa3("192.168.1.100", "ftp");
		assert(sa3.host() == "192.168.1.100");
		assert(sa3.port() == 21);
		
		Address sa7("192.168.2.120:88");
		assert(sa7.host() == "192.168.2.120");
		assert(sa7.port() == 88);

		Address sa8("[192.168.2.120]:88");
		assert(sa8.host() == "192.168.2.120");
		assert(sa8.port() == 88);

		try {
			Address sa3("192.168.1.100", "f00bar");
			assert(0 && "bad service name - must throw");
		}
		catch (std::exception&) {}

		try {
			Address sa6("192.168.2.120", "80000");
			assert(0 && "invalid port - must throw");
		}
		catch (std::exception&) {}

		try {
			Address sa5("192.168.2.260", 80);
			assert(0 && "invalid address - must throw");
		}
		catch (std::exception&) {}

		try {
			Address sa9("[192.168.2.260:", 88);
			assert(0 && "invalid address - must throw");
		}
		catch (std::exception&) {}

		try {
			Address sa9("[192.168.2.260]");
			assert(0 && "invalid address - must throw");
		}
		catch (std::exception&) {}
	}	
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Network_Adapters_Test"));

#if defined (ACE_WIN32)
#if !defined (ACE_HAS_WINCE)
  SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlHandler, TRUE);
#endif
#else /* #if defined (ACE_WIN32) */
  // Set a handler for SIGSEGV signal to call for abort.
  ACE_Sig_Action sa1 ((ACE_SignalHandler) sigsegv_handler, SIGSEGV);
#endif /* #if defined (ACE_WIN32) */
  if (::parse_args (argc, argv) == -1)
    {
      return -1;
    }

  ACE_Reactor * main_reactor = 0;
  ACE_NEW_RETURN (main_reactor, ACE_Reactor, -1);

  (void) ACE_High_Res_Timer::global_scale_factor ();

  // Change the source of time in the reactor to the high-resolution
  // timer.  Why does this test require such precision for a 1 second
  // timer is beyond me ...  I think it is a cut&paste error.
  //
  // The use of auto_ptr<> is optional, ACE uses dangerous memory
  // management idioms everywhere, I thought I could demonstrate how
  // to do it right in at least one test.  Notice the lack of
  // ACE_NEW_RETURN, that monstrosity has no business in proper C++
  // code ...
  auto_ptr<ACE_Timer_Heap_Variable_Time_Source> tq(
      new ACE_Timer_Heap_Variable_Time_Source);
  // ... notice how the policy is in the derived timer queue type.
  // The abstract timer queue does not have a time policy ...
  tq->set_time_policy(&ACE_High_Res_Timer::gettimeofday_hr);
  // ... and then the timer queue is replaced.  Strangely, the reactor
  // does *not* copy the timers, it just deletes the existing timer
  // queue ....
  main_reactor->timer_queue(tq.get());
  // ... the reactor does not assume ownership

  /**
   * Stop_Handler's is supposed to stop the activity of all
   * handlers by a SIGINT signal.  We create and activate here an object of
   * Stop_Handler and pass an instance of reactor (main_reactor),
   * running demultiplexing event loop in the "main thread".
   */
  Stop_Handler* stop_handler = 0;
  ACE_NEW_RETURN (stop_handler, Stop_Handler (main_reactor), -1);
  if (stop_handler->open () == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) %p\n"),
                  ACE_TEXT ("main() - stop_handler->open")));
      ACE_OS::exit(-2);
    }

  ACE_TCHAR *ping_status = 0;
  ACE_NEW_RETURN (ping_status, ACE_TCHAR[number_of_ping_points], -1);

  // wait_echo_reply_timer is in msec
  int seconds = 0;
  int milliseconds = 0;
  seconds = wait_echo_reply_timer / 1000;
  milliseconds =  wait_echo_reply_timer % 1000;
  ACE_Time_Value const wait_timer (seconds, milliseconds);

  Echo_Handler *ping_handler = 0;
  ACE_NEW_RETURN (ping_handler, Echo_Handler, -1);

  if (ACE_OS::strlen (local_ip_to_bind))
    {
      // We are willing to bind the raw-socket to a certain adapter,
      // probably because we are willing to check connectivity/etc
      // of the local adapter.
      ACE_INET_Addr local_adapter;
      local_adapter.set ((u_short) 0, local_ip_to_bind);
      if (ping_handler->open (main_reactor,
                              wait_timer,
                              ping_points_addrs,
                              number_of_ping_points,
                              ping_status,
                              2,  // max_attempts_number
                              local_adapter) == -1)
        {
          int res = 0;
          // If this process doesn't have privileges to open a raw socket, log
          // a warning instead of an error.
          if (errno == EPERM || errno == EACCES)
            {
              ACE_ERROR ((LM_WARNING,
                          ACE_TEXT ("(%P|%t) main() - ping_handler->open: ")
                          ACE_TEXT ("insufficient privs to run this test\n")));
            }
          else
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("(%P|%t) %p\n"),
                          ACE_TEXT ("main() - ping_handler->open")));
              res = -4;
            }
          delete ping_handler;
          delete [] ping_status;
          delete main_reactor;
          delete stop_handler;

          ACE_END_TEST;
          return res;
        }
    }
  else
    {
      // Binding to a local adapter is not of our interest. We just
      // are willing to check all these remote IPs, to monitor, that
      // they are alive.
      if (ping_handler->open (main_reactor,
                              wait_timer,
                              ping_points_addrs,
                              number_of_ping_points,
                              ping_status,
                              2) == -1)   // max_attempts_number
        {
          int res = 0;
          if (errno == EPERM || errno == EACCES)
            {
              ACE_ERROR ((LM_WARNING,
                          ACE_TEXT ("(%P|%t) main() - ping_handler->open: ")
                          ACE_TEXT ("insufficient privs to run this test\n")));
            }
          else
            {
              ACE_ERROR ((LM_ERROR,
                          ACE_TEXT ("(%P|%t) %p\n"),
                          ACE_TEXT ("main() - ping_handler->open")));
              res = -4;
            }
          delete ping_handler;
          delete [] ping_status;
          delete main_reactor;
          delete stop_handler;

          ACE_END_TEST;
          return res;
        }
    }

  Repeats_Handler *repeats_handler = 0;
  ACE_NEW_RETURN (repeats_handler, Repeats_Handler, -1);
  if (repeats_handler->open (ping_handler,
                             main_reactor,
                             repeats_seconds_timer) == -1)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("(%P|%t) %p\n"),
                  ACE_TEXT ("main() - repeats_handler->open")));

      delete repeats_handler;
      delete ping_handler;
      delete [] ping_status;
      delete main_reactor;
      delete stop_handler;

      ACE_END_TEST;
      return -4;
    }

  stop_handler->register_handler (repeats_handler);
  stop_handler->register_handler (ping_handler);

  // Demultiplexing event loop of the main_reactor.
  while (main_reactor->reactor_event_loop_done () == 0)
    {
      main_reactor->run_reactor_event_loop ();
    }

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT ("(%P|%t|%T) \"Network_Adapters_Test\" main() - ")
              ACE_TEXT ("out of reactor's loop.\n")));

  delete repeats_handler;
  delete ping_handler;
  delete [] ping_status;
  delete main_reactor;
  delete stop_handler;

  ACE_END_TEST;
  return 0;
}