Esempio n. 1
0
int main_0004_conf (int argc, char **argv) {
	rd_kafka_t *rk;
	rd_kafka_topic_t *rkt;
	rd_kafka_conf_t *ignore_conf, *conf, *conf2;
	rd_kafka_topic_conf_t *ignore_topic_conf, *tconf, *tconf2;
	char errstr[512];
	const char **arr_orig, **arr_dup;
	size_t cnt_orig, cnt_dup;
	int i;
        const char *topic;
	static const char *gconfs[] = {
		"message.max.bytes", "12345", /* int property */
		"client.id", "my id", /* string property */
		"debug", "topic,metadata,interceptor", /* S2F property */
		"topic.blacklist", "__.*", /* #778 */
                "auto.offset.reset", "earliest", /* Global->Topic fallthru */
#if WITH_ZLIB
		"compression.codec", "gzip", /* S2I property */
#endif
		NULL
	};
	static const char *tconfs[] = {
		"request.required.acks", "-1", /* int */
		"auto.commit.enable", "false", /* bool */
		"auto.offset.reset", "error",  /* S2I */
		"offset.store.path", "my/path", /* string */
		NULL
	};

	test_conf_init(&ignore_conf, &ignore_topic_conf, 10);
	rd_kafka_conf_destroy(ignore_conf);
	rd_kafka_topic_conf_destroy(ignore_topic_conf);

        topic = test_mk_topic_name("0004", 0);

	/* Set up a global config object */
	conf = rd_kafka_conf_new();

        for (i = 0 ; gconfs[i] ; i += 2) {
                if (rd_kafka_conf_set(conf, gconfs[i], gconfs[i+1],
                                      errstr, sizeof(errstr)) !=
                    RD_KAFKA_CONF_OK)
                        TEST_FAIL("%s\n", errstr);
        }

	rd_kafka_conf_set_dr_cb(conf, dr_cb);
	rd_kafka_conf_set_error_cb(conf, error_cb);
        /* interceptor configs are not exposed as strings or in dumps
         * so the dump verification step will not cover them, but valgrind
         * will help track down memory leaks/use-after-free etc. */
        rd_kafka_conf_interceptor_add_on_new(conf, "testic", my_on_new, NULL);

	/* Set up a topic config object */
	tconf = rd_kafka_topic_conf_new();

	rd_kafka_topic_conf_set_partitioner_cb(tconf, partitioner);
	rd_kafka_topic_conf_set_opaque(tconf, (void *)0xbeef);

	for (i = 0 ; tconfs[i] ; i += 2) {
		if (rd_kafka_topic_conf_set(tconf, tconfs[i], tconfs[i+1],
				      errstr, sizeof(errstr)) !=
		    RD_KAFKA_CONF_OK)
			TEST_FAIL("%s\n", errstr);
	}


	/* Verify global config */
	arr_orig = rd_kafka_conf_dump(conf, &cnt_orig);
	conf_verify(__LINE__, arr_orig, cnt_orig, gconfs);

	/* Verify copied global config */
	conf2 = rd_kafka_conf_dup(conf);
	arr_dup = rd_kafka_conf_dump(conf2, &cnt_dup);
	conf_verify(__LINE__, arr_dup, cnt_dup, gconfs);
	conf_cmp("global", arr_orig, cnt_orig, arr_dup, cnt_dup);
	rd_kafka_conf_dump_free(arr_orig, cnt_orig);
	rd_kafka_conf_dump_free(arr_dup, cnt_dup);

	/* Verify topic config */
	arr_orig = rd_kafka_topic_conf_dump(tconf, &cnt_orig);
	conf_verify(__LINE__, arr_orig, cnt_orig, tconfs);

	/* Verify copied topic config */
	tconf2 = rd_kafka_topic_conf_dup(tconf);
	arr_dup = rd_kafka_topic_conf_dump(tconf2, &cnt_dup);
	conf_verify(__LINE__, arr_dup, cnt_dup, tconfs);
	conf_cmp("topic", arr_orig, cnt_orig, arr_dup, cnt_dup);
	rd_kafka_conf_dump_free(arr_orig, cnt_orig);
	rd_kafka_conf_dump_free(arr_dup, cnt_dup);


	/*
	 * Create kafka instances using original and copied confs
	 */

	/* original */
        TEST_ASSERT(on_new_call_cnt == 0, "expected 0 on_new call, not %d",
                    on_new_call_cnt);
        on_new_call_cnt = 0;
	rk = test_create_handle(RD_KAFKA_PRODUCER, conf);
        TEST_ASSERT(on_new_call_cnt == 1, "expected 1 on_new call, not %d",
                on_new_call_cnt);

	rkt = rd_kafka_topic_new(rk, topic, tconf);
	if (!rkt)
		TEST_FAIL("Failed to create topic: %s\n",
			  rd_strerror(errno));

	rd_kafka_topic_destroy(rkt);
	rd_kafka_destroy(rk);

	/* copied */
        on_new_call_cnt = 0;
	rk = test_create_handle(RD_KAFKA_PRODUCER, conf2);
        TEST_ASSERT(on_new_call_cnt == 1, "expected 1 on_new call, not %d",
                on_new_call_cnt);

        if (on_new_call_cnt != 1)
                TEST_FAIL("Expected on_new call count to be %d, not %d",
                          1, on_new_call_cnt);

	rkt = rd_kafka_topic_new(rk, topic, tconf2);
	if (!rkt)
		TEST_FAIL("Failed to create topic: %s\n",
			  rd_strerror(errno));
	rd_kafka_topic_destroy(rkt);
	rd_kafka_destroy(rk);


	/* Incremental S2F property.
	 * NOTE: The order of fields returned in get() is hardcoded here. */
	{
		static const char *s2fs[] = {
			"generic,broker,queue,cgrp",
			"generic,broker,queue,cgrp",

			"-broker,+queue,topic",
			"generic,topic,queue,cgrp",

			"-all,security,-fetch,+metadata",
			"metadata,security",

			NULL
		};

		TEST_SAY("Incremental S2F tests\n");
		conf = rd_kafka_conf_new();

		for (i = 0 ; s2fs[i] ; i += 2) {
			const char *val;

			TEST_SAY("  Set: %s\n", s2fs[i]);
			test_conf_set(conf, "debug", s2fs[i]);
			val = test_conf_get(conf, "debug");
			TEST_SAY("  Now: %s\n", val);

			if (strcmp(val, s2fs[i+1]))
				TEST_FAIL_LATER("\n"
						"Expected: %s\n"
						"     Got: %s",
						s2fs[i+1], val);
		}
		rd_kafka_conf_destroy(conf);
	}

	/* Canonical int values, aliases, s2i-verified strings */
	{
		static const struct {
			const char *prop;
			const char *val;
			const char *exp;
			int is_global;
		} props[] = {
			{ "request.required.acks", "0", "0" },
			{ "request.required.acks", "-1", "-1" },
			{ "request.required.acks", "1", "1" },
			{ "acks", "3", "3" }, /* alias test */
			{ "request.required.acks", "393", "393" },
			{ "request.required.acks", "bad", NULL },
			{ "request.required.acks", "all", "-1" },
                        { "request.required.acks", "all", "-1", 1/*fallthru*/ },
			{ "acks", "0", "0" }, /* alias test */
#if WITH_SASL
			{ "sasl.mechanisms", "GSSAPI", "GSSAPI", 1 },
			{ "sasl.mechanisms", "PLAIN", "PLAIN", 1  },
			{ "sasl.mechanisms", "GSSAPI,PLAIN", NULL, 1  },
			{ "sasl.mechanisms", "", NULL, 1  },
#endif
			{ NULL }
		};

		TEST_SAY("Canonical tests\n");
		tconf = rd_kafka_topic_conf_new();
		conf = rd_kafka_conf_new();

		for (i = 0 ; props[i].prop ; i++) {
			char dest[64];
			size_t destsz;
			rd_kafka_conf_res_t res;

			TEST_SAY("  Set: %s=%s expect %s (%s)\n",
				 props[i].prop, props[i].val, props[i].exp,
                                 props[i].is_global ? "global":"topic");


			/* Set value */
			if (props[i].is_global)
				res = rd_kafka_conf_set(conf,
						      props[i].prop,
						      props[i].val,
						      errstr, sizeof(errstr));
			else
				res = rd_kafka_topic_conf_set(tconf,
							      props[i].prop,
							      props[i].val,
							      errstr,
							      sizeof(errstr));
			if ((res == RD_KAFKA_CONF_OK ? 1:0) !=
			    (props[i].exp ? 1:0))
				TEST_FAIL("Expected %s, got %s",
					  props[i].exp ? "success" : "failure",
					  (res == RD_KAFKA_CONF_OK ? "OK" :
					   (res == RD_KAFKA_CONF_INVALID ? "INVALID" :
					    "UNKNOWN")));

			if (!props[i].exp)
				continue;

			/* Get value and compare to expected result */
			destsz = sizeof(dest);
			if (props[i].is_global)
				res = rd_kafka_conf_get(conf,
							props[i].prop,
							dest, &destsz);
			else
				res = rd_kafka_topic_conf_get(tconf,
							      props[i].prop,
							      dest, &destsz);
			TEST_ASSERT(res == RD_KAFKA_CONF_OK,
				    ".._conf_get(%s) returned %d",
                                    props[i].prop, res);

			TEST_ASSERT(!strcmp(props[i].exp, dest),
				    "Expected \"%s\", got \"%s\"",
				    props[i].exp, dest);
		}
		rd_kafka_topic_conf_destroy(tconf);
		rd_kafka_conf_destroy(conf);
	}

        do_test_kafka_new_failures();

	return 0;
}
Esempio n. 2
0
void testTrue(void)
{
    TEST_ASSERT(1);
 
    TEST_ASSERT_TRUE(1);
}
static void StartThread( void* arg )
{
  KMutex locks[NESTING_DEPTH - 1];
  DonorThreadParams donorParams[ NESTING_DEPTH ];
  TestData* pTestData = ( TestData* ) arg;

  for (uint32_t i = 0; i < NESTING_DEPTH - 1; i++) {
    char tmp[30];
    bool workerMutexCreateResult = false;
    sprintf_s( tmp, sizeof(tmp), "Mutex %d", i );
    workerMutexCreateResult = KMutexCreate( &locks[ i ], tmp );
  }

  KMutexLock( &locks[0], WAIT_FOREVER );
  ConsoleLogLine( "%s got lock, My Priority: %d", s_data.threads[0].threadName,
       KThreadGetPriority( &pTestData->threads[ 0 ] ) );

  for ( uint32_t i = 1; i < NESTING_DEPTH; i++)
  {
    char name[16];
    int thread_priority;
    snprintf (name, sizeof name, "thread %d", i);
    thread_priority = PRI_MIN + i * 3;

    donorParams[ i ].lockPair.first = i < NESTING_DEPTH - 1 ? locks + i : NULL;
    donorParams[ i ].lockPair.second = locks + i - 1;
    donorParams[ i ].i = i;
    donorParams[ i ].pThread = &pTestData->threads[ i ];
    donorParams[ i ].pTestData = pTestData;
    KThreadCreateParams params = {
        .fn = DonorThreadFunction,
        .pStack = pTestData->stacks[ i ],
        .pThreadName = name,
        .stackSizeInBytes = sizeof( pTestData->stacks[ i ] ),
        .threadArg = &donorParams[i],
        .threadPriority = thread_priority
    };
    ConsoleLogLine( "Starting %s with priority: %d", name, thread_priority );
    TEST_ASSERT( KThreadCreate( &pTestData->threads[ i ], &params ) );
    /*
    ConsoleLogLine ("%s should have priority %d.  Actual priority: %d.",
         name, thread_priority, KThreadGetPriority( &pTestData->threads[ i ] ) );
    snprintf (name, sizeof name, "interloper %d", i);
    interloperParams[ i ].i = i;
    interloperParams[ i ].pThread = &pTestData->interloperThreads[ i ];
    interloperParams[ i ].pTestData = pTestData;
    KThreadCreateParams paramsInterloper = {
        .fn = InterloperThreadFunction,
        .pStack = pTestData->interloperStacks[ i ],
        .pThreadName = name,
        .stackSizeInBytes = sizeof( pTestData->interloperStacks[ i ] ),
        .threadArg = &interloperParams[ i ],
        .threadPriority = thread_priority - 1,
    };
    TEST_ASSERT( KThreadCreate( &pTestData->interloperThreads[ i ], &paramsInterloper ) );
     */
  }
  TEST_ASSERT_EQUAL_INT( NESTING_DEPTH - 1, pTestData->currentThreadIndexToRelease );
  KMutexUnlock( &locks[ 0 ] );
  /*
  ConsoleLogLine("%s finishing with priority %d.\n", KThreadGetName( &pTestData->threads[ 0 ] ),
       KThreadGetPriority( &pTestData->threads[ 0 ] ) );
       */
  TEST_ASSERT( KThreadJoin( &pTestData->threads[ 1 ] ) && KThreadJoin( &pTestData->interloperThreads[ 1 ] ) );
}

static void TestPriorityDonateChain( void )
{
  TestData* pTestData = &s_data;
  pTestData->currentThreadIndexToRelease = 0;
  KThreadCreateParams startThread = {
      .fn = StartThread,
      .pStack = pTestData->stacks[ 0 ],
      .pThreadName = "StartThread",
      .stackSizeInBytes = THREAD_STACK_SIZE,
      .threadArg = pTestData,
      .threadPriority = PRI_MIN,
  };
  pTestData->currentThreadIndexToRelease = 0;
  bool startThreadCreateResult = KThreadCreate( &pTestData->threads[ 0 ], &startThread );
  TEST_ASSERT( startThreadCreateResult );
  //Test ends when StartThread Ends
  bool waitForStartThreadEnd = KThreadJoin( &pTestData->threads[ 0 ] );
  TEST_ASSERT( waitForStartThreadEnd );
}

static void
DonorThreadFunction( void *args )
{
  DonorThreadParams* pParams = ( DonorThreadParams* )args;

  if (pParams->lockPair.first)
    KMutexLock(pParams->lockPair.first, WAIT_FOREVER );
  ConsoleLogLine( "%s priority %d, Actual priority: %d\n",
       KThreadGetName( pParams->pThread ), KThreadGetPriority( pParams->pThread ) );
  TEST_ASSERT_EQUAL_INT( pParams->i - 1, pParams->pTestData->currentThreadIndexToRelease );
  pParams->pTestData->currentThreadIndexToRelease = pParams->i;
  KMutexLock(pParams->lockPair.second, WAIT_FOREVER );
  TEST_ASSERT_EQUAL_INT( NESTING_DEPTH - pParams->i, pParams->pTestData->currentThreadIndexToRelease );
  pParams->pTestData->currentThreadIndexToRelease = NESTING_DEPTH - ( pParams->i + 1 );
  KMutexUnlock(pParams->lockPair.second);
  /*
  ConsoleLogLine ("%s should have priority %d. Actual priority: %d\n",
       KThreadGetName( pParams->pThread ), (NESTING_DEPTH - 1) * 3,
       KThreadGetPriority( pParams->pThread ) );
       */

  if (pParams->lockPair.first)
    KMutexUnlock(pParams->lockPair.first);

/*
  ConsoleLogLine("%s finishing with priority %d.\n", KThreadGetName( pParams->pThread ),
       KThreadGetPriority( pParams->pThread ) );
       */
}
Esempio n. 4
0
void t0()
{
    // ecst::fixed_set<100> ss;
    vrm::core::fixed_vector_sparse_set<unsigned int, 100> ss;

    TEST_ASSERT(ss.empty());
    TEST_ASSERT_OP(ss.size(), ==, 0);

    TEST_ASSERT(ss.add(0) == true);
    TEST_ASSERT(ss.add(0) == false);
    TEST_ASSERT(ss.add(0) == false);

    TEST_ASSERT(!ss.empty());
    TEST_ASSERT_OP(ss.size(), ==, 1);
    TEST_ASSERT(ss.has(0));
    TEST_ASSERT(!ss.has(1));
    TEST_ASSERT(!ss.has(2));

    TEST_ASSERT(ss.add(1) == true);
    TEST_ASSERT(ss.add(1) == false);

    TEST_ASSERT(!ss.empty());
    TEST_ASSERT_OP(ss.size(), ==, 2);
    TEST_ASSERT(ss.has(0));
    TEST_ASSERT(ss.has(1));
    TEST_ASSERT(!ss.has(2));

    TEST_ASSERT(ss.add(2) == true);
    TEST_ASSERT(ss.add(2) == false);

    TEST_ASSERT(!ss.empty());
    TEST_ASSERT_OP(ss.size(), ==, 3);
    TEST_ASSERT(ss.has(0));
    TEST_ASSERT(ss.has(1));
    TEST_ASSERT(ss.has(2));
}
Esempio n. 5
0
int test_main(int, char **)
{
	typedef ion::playlists < ion::flat_playlist > playlists_t;
	typedef ion::filter_playlist < playlists_t > filter_playlist_t;

	ion::flat_playlist::unique_ids_t unique_ids_;

	ion::flat_playlist *playlist1 = new ion::flat_playlist(unique_ids_);
	playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar11"), *ion::parse_metadata("{ \"title\" : \"hello 441\" }"), false), false);
	playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar12"), *ion::parse_metadata("{ \"title\" : \"abc def\" }"), false), false);
	playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar13"), *ion::parse_metadata("{ \"title\" : \"lorem ipsum\" }"), false), false);
	playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar14"), *ion::parse_metadata("{ \"title\" : \"max mustermann\" }"), false), false);

	ion::flat_playlist *playlist2 = new ion::flat_playlist(unique_ids_);
	playlist2->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar21"), *ion::parse_metadata("{ \"title\" : \"ugauga\" }"), false), false);
	playlist2->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar22"), *ion::parse_metadata("{ \"title\" : \"john smith\" }"), false), false);
	playlist2->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar23"), *ion::parse_metadata("{ \"title\" : \"test c55\" }"), false), false);
	playlist2->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://bar24"), *ion::parse_metadata("{ \"title\" : \"xxycz\" }"), false), false);

	playlists_t playlists;
	playlists.add_playlist(playlists_t::playlist_ptr_t(playlist1));
	playlists.add_playlist(playlists_t::playlist_ptr_t(playlist2));

	filter_playlist_t filter_playlist(playlists, boost::phoenix::bind(&match, boost::phoenix::arg_names::arg1));


	TEST_VALUE(ion::get_num_entries(filter_playlist), 3);
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 0)).get_path(), "bar12");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 1)).get_path(), "bar23");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 2)).get_path(), "bar24");

	{
		// testing uri-based retrieval and incompatibility marking
		// since the playlist adds an id option to the URI, it is retrieved from one of the entries instead of created manually
		ion::uri test_uri = boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 1));
		TEST_ASSERT(ion::get_metadata_for(filter_playlist, test_uri), "");

		ion::mark_backend_resource_incompatibility(filter_playlist, test_uri, "test_backend");
		TEST_VALUE(boost::fusion::at_c < 2 > (*ion::get_entry(filter_playlist, 1)), true);
	}

	// The following code tests the signal relay in filter_playlist
	// Internally, if one of the playlists that have URIs in the filter playlist proxy entry list get altered,
	// the filter playlist is notified, and changes its proxy entry list accordingly.

	playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://extra"), *ion::parse_metadata("{ \"title\" : \"ccccc\" }"), false), true);
	TEST_VALUE(ion::get_num_entries(filter_playlist), 4);
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 0)).get_path(), "bar12");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 1)).get_path(), "extra");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 2)).get_path(), "bar23");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 3)).get_path(), "bar24");

	playlist2->remove_entry(*ion::get_entry(filter_playlist, 2), true);
	//print_playlist(filter_playlist);
	TEST_VALUE(ion::get_num_entries(filter_playlist), 3);
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 0)).get_path(), "bar12");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 1)).get_path(), "extra");
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 2)).get_path(), "bar24");

	playlists.remove_playlist(*playlist1);
	TEST_VALUE(ion::get_num_entries(filter_playlist), 1);
	TEST_VALUE(boost::fusion::at_c < 0 > (*ion::get_entry(filter_playlist, 0)).get_path(), "bar24");


	{
		// The following code tests correct signal disconnection

		playlists_t playlists_;

		ion::flat_playlist *playlist1 = new ion::flat_playlist(unique_ids_);
		filter_playlist_t *filter_playlist_ = new filter_playlist_t(playlists_, boost::phoenix::bind(&match, boost::phoenix::arg_names::arg1));
		playlists_.add_playlist(playlists_t::playlist_ptr_t(playlist1));
		delete filter_playlist_;
		playlist1->add_entry(ion::flat_playlist::entry_t(ion::uri("foo://abc"), *ion::parse_metadata("{ \"title\" : \"ccccc\" }"), false), true);
	}


	return 0;
}
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( DomainTransporter, Cutoff )
{
    typedef Tpetra::Vector<double,int,long> VectorType;
    typedef MCLS::VectorTraits<VectorType> VT;
    typedef Tpetra::CrsMatrix<double,int,long> MatrixType;
    typedef MCLS::MatrixTraits<VectorType,MatrixType> MT;
    typedef MCLS::AdjointHistory<long> HistoryType;
    typedef std::mt19937 rng_type;
    typedef MCLS::AdjointTally<VectorType> TallyType;
    typedef MCLS::AlmostOptimalDomain<VectorType,MatrixType,rng_type,TallyType>
	DomainType;

    Teuchos::RCP<const Teuchos::Comm<int> > comm = 
	Teuchos::DefaultComm<int>::getComm();
    int comm_size = comm->getSize();
    int comm_rank = comm->getRank();

    int local_num_rows = 10;
    int global_num_rows = local_num_rows*comm_size;
    Teuchos::RCP<const Tpetra::Map<int,long> > map = 
	Tpetra::createUniformContigMap<int,long>( global_num_rows, comm );

    // Build the linear operator and solution vector.
    Teuchos::RCP<MatrixType> A = Tpetra::createCrsMatrix<double,int,long>( map );
    Teuchos::Array<long> global_columns( 1 );
    Teuchos::Array<double> values( 1, 0.5 );
    for ( int i = 0; i < global_num_rows; ++i )
    {
	if ( i >= local_num_rows*comm_rank && i < local_num_rows*(comm_rank+1) )
	{
	    global_columns[0] = i;
	    A->insertGlobalValues( i, global_columns(), values() );
	}
    }
    A->fillComplete();

    Teuchos::RCP<VectorType> x = MT::cloneVectorFromMatrixRows( *A );
    Teuchos::RCP<MatrixType> A_T = MT::copyTranspose(*A);

    // Build the adjoint domain.
    Teuchos::ParameterList plist;
    plist.set<int>( "History Length", 1 );
    Teuchos::RCP<DomainType> domain = Teuchos::rcp( new DomainType( A_T, x, plist ) );
    Teuchos::RCP<MCLS::PRNG<rng_type> > rng = Teuchos::rcp(
	new MCLS::PRNG<rng_type>( comm->getRank() ) );
    domain->setRNG( rng );

    // Build the domain transporter.
    double weight = 3.0; 
    MCLS::DomainTransporter<DomainType> transporter( domain );

    // Transport histories through the domain.
    for ( int i = 0; i < global_num_rows; ++i )
    {
	if ( i >= local_num_rows*comm_rank && i < local_num_rows*(comm_rank+1) )
	{
	    HistoryType history( i, i, weight );
	    history.live();
	    transporter.transport( history );

	    TEST_EQUALITY( history.globalState(), i );
	    TEST_EQUALITY( history.localState(), i - local_num_rows*comm_rank );
	    TEST_EQUALITY( history.weight(), weight / 2 );
	    TEST_EQUALITY( history.event(), MCLS::Event::CUTOFF );
	    TEST_ASSERT( !history.alive() );
	}
    }

    // Check the tally.
    Teuchos::ArrayRCP<const double> x_view = VT::view( *x );
    double x_val = weight;
    for ( int i = 0; i < local_num_rows; ++i )
    {
	TEST_EQUALITY( x_view[i], x_val );
    }
}
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( DomainTransporter, Cutoff2 )
{
    typedef Epetra_Vector VectorType;
    typedef MCLS::VectorTraits<VectorType> VT;
    typedef Epetra_RowMatrix MatrixType;
    typedef MCLS::MatrixTraits<VectorType,MatrixType> MT;
    typedef MCLS::AdjointHistory<int> HistoryType;
    typedef std::mt19937 rng_type;
    typedef MCLS::AdjointDomain<VectorType,MatrixType,rng_type> DomainType;

    Teuchos::RCP<const Teuchos::Comm<int> > comm = 
	Teuchos::DefaultComm<int>::getComm();
    Teuchos::RCP<Epetra_Comm> epetra_comm = getEpetraComm( comm );
    int comm_size = comm->getSize();
    int comm_rank = comm->getRank();

    int local_num_rows = 10;
    int global_num_rows = local_num_rows*comm_size;
    Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(
	new Epetra_Map( global_num_rows, 0, *epetra_comm ) );

    // Build the linear operator and solution vector.
    Teuchos::RCP<Epetra_CrsMatrix> A = 	
	Teuchos::rcp( new Epetra_CrsMatrix( Copy, *map, 0 ) );

    Teuchos::Array<int> global_columns( 1 );
    Teuchos::Array<double> values( 1 );
    for ( int i = 1; i < global_num_rows; ++i )
    {
	global_columns[0] = i-1;
	values[0] = -0.5;
	A->InsertGlobalValues( i, global_columns().size(),
			       &values[0], &global_columns[0] );
    }
    global_columns[0] = global_num_rows-1;
    values[0] = -0.5;
    A->InsertGlobalValues( global_num_rows-1, global_columns.size(),
			   &values[0], &global_columns[0] );
    A->FillComplete();

    Teuchos::RCP<MatrixType> B = MT::copyTranspose(*A);
    Teuchos::RCP<VectorType> x = MT::cloneVectorFromMatrixRows( *A );

    // Build the adjoint domain.
    Teuchos::ParameterList plist;
    plist.set<int>( "Overlap Size", 2 );
    Teuchos::RCP<DomainType> domain = Teuchos::rcp( new DomainType( B, x, plist ) );
    Teuchos::RCP<MCLS::PRNG<rng_type> > rng = Teuchos::rcp(
	new MCLS::PRNG<rng_type>( comm->getRank() ) );
    domain->setRNG( rng );

    // Build the domain transporter.
    double weight = 3.0; 
    double relative_cutoff = weight / 4 + 0.01;
    MCLS::DomainTransporter<DomainType> transporter( domain, plist );
    domain->setCutoff( relative_cutoff );

    // Transport histories through the domain.
    for ( int i = 0; i < global_num_rows-2; ++i )
    {
	if ( comm_rank == comm_size - 1 )
	{
	    if ( i >= local_num_rows*comm_rank && i < local_num_rows*(comm_rank+1) )
	    {
		HistoryType history( i, i, weight );
		history.live();
		transporter.transport( history );

		TEST_EQUALITY( history.globalState(), i+2 );
		TEST_EQUALITY( history.weight(), weight / 4 );
		TEST_EQUALITY( history.event(), MCLS::Event::CUTOFF );
		TEST_ASSERT( !history.alive() );
	    }
	}
	else
	{
	    if ( i >= local_num_rows*comm_rank && i < 1+local_num_rows*(comm_rank+1) )
	    {
		HistoryType history( i, i, weight );
		history.live();
		transporter.transport( history );

		TEST_EQUALITY( history.globalState(), i+2 );
		TEST_EQUALITY( history.weight(), weight / 4 );
		TEST_EQUALITY( history.event(), MCLS::Event::CUTOFF );
		TEST_ASSERT( !history.alive() );
	    }
	}
    }

    // Check the tally.
    domain->domainTally()->combineSetTallies( comm );
    Teuchos::ArrayRCP<const double> x_view = 
        VT::view( *x );
    double x_val = weight;
    for ( int i = 0; i < local_num_rows; ++i )
    {
	if ( comm_rank == comm_size-1 && i == local_num_rows-1 )
	{
	    TEST_EQUALITY( x_view[i], 0.0 );
	}
	else if ( comm_rank == comm_size-1 && i == local_num_rows-2 )
	{
	    TEST_EQUALITY( x_view[i], 3.0/2.0 );
	}
	else if ( comm_rank == 0 && i == 0 )
	{
	    TEST_EQUALITY( x_view[i], x_val );
	}
	else if ( comm_rank == 0 || i > 2 )
	{
	    TEST_EQUALITY( x_view[i], 3.0*x_val/2.0 );
	}
	else
	{
	    TEST_EQUALITY( x_view[i], 3.0*x_val );
	}
    }
}
Esempio n. 8
0
int main(int n, char **p)
{
	Step::RefPtr<ifc2x3::ExpressDataSet> eds ;
	try
	{
		std::cout << "Creating ExpressDataSet" << std::endl;
		eds = new ifc2x3::ExpressDataSet;
	}
	catch (const std::exception& e)
	{
		TEST_FAILURE((std::string("Exception : ") + e.what()).c_str());
	}

	TEST_VALIDITY(eds);

	LOG_DEBUG(std::endl << "Test with no Scale" << std::endl);
	Step::RefPtr<ifc2x3::IfcCartesianTransformationOperator2DnonUniform> CTOperator2DnonUniform1 = eds->createIfcCartesianTransformationOperator2DnonUniform();
	TEST_VALIDITY(CTOperator2DnonUniform1);
	
	Step::RefPtr< ifc2x3::IfcDirection > Axis11 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal11;
	ListReal11.push_back(1.0);
	ListReal11.push_back(0.0);
	Axis11->setDirectionRatios(ListReal11);

	CTOperator2DnonUniform1->setAxis1(Axis11);

	Step::RefPtr< ifc2x3::IfcDirection > Axis21 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal21;
	ListReal21.push_back(0.0);
	ListReal21.push_back(1.0);
	Axis21->setDirectionRatios(ListReal21);

	CTOperator2DnonUniform1->setAxis2(Axis21);

	
	LOG_DEBUG("getScale2 = "<< Step::isUnset( CTOperator2DnonUniform1->getScale2()) << std::endl);
	TEST_ASSERT(Step::isUnset( CTOperator2DnonUniform1->getScale2()));
	LOG_DEBUG("getScl2 = "<< CTOperator2DnonUniform1->getScl2() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform1->getScl2()==1.0);
	LOG_DEBUG("getScl = "<< CTOperator2DnonUniform1->getScl() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform1->getScl()==1.0);

///////////////////////////////////////////////////////////////////////////////////////////////////////////
	LOG_DEBUG(std::endl << "Test with CTOperator2DnonUniform2->setScale(2.5);" << std::endl);
	Step::RefPtr<ifc2x3::IfcCartesianTransformationOperator2DnonUniform> CTOperator2DnonUniform2 = eds->createIfcCartesianTransformationOperator2DnonUniform();
	TEST_VALIDITY(CTOperator2DnonUniform2);

	Step::RefPtr< ifc2x3::IfcDirection > Axis12 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal12;
	ListReal12.push_back(2.0);
	ListReal12.push_back(1.0);
	Axis12->setDirectionRatios(ListReal12);

	CTOperator2DnonUniform2->setAxis1(Axis12);

	Step::RefPtr< ifc2x3::IfcDirection > Axis22 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal22;
	ListReal22.push_back(4.0);
	ListReal22.push_back(1.0);
	Axis22->setDirectionRatios(ListReal22);

	CTOperator2DnonUniform2->setAxis2(Axis22);

	CTOperator2DnonUniform2->setScale(2.5);
	LOG_DEBUG("getScale2 = "<< Step::isUnset( CTOperator2DnonUniform2->getScale2()) << std::endl);
	TEST_ASSERT(Step::isUnset( CTOperator2DnonUniform2->getScale2()));
	LOG_DEBUG("getScl2 = "<< CTOperator2DnonUniform2->getScl2() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform2->getScl2()==2.5);
	LOG_DEBUG("getScl = "<< CTOperator2DnonUniform2->getScl() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform2->getScl()==2.5);


	CTOperator2DnonUniform2->setScale2(4.5);
	LOG_DEBUG(std::endl << "Test with CTOperator2DnonUniform2->setScale2(4.5);" << std::endl);

	LOG_DEBUG("getScale2 = "<< CTOperator2DnonUniform2->getScale2() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform2->getScale2()==4.5);
	LOG_DEBUG("getScl2 = "<< CTOperator2DnonUniform2->getScl2() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform2->getScl2()==4.5);
	LOG_DEBUG("getScl = "<< CTOperator2DnonUniform2->getScl() << std::endl);
	TEST_ASSERT(CTOperator2DnonUniform2->getScl()==2.5);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	std::cout << std::endl << "Failure : " << failure_results << " Success : " << success_results << std::endl;

	return failure_results;
}
Esempio n. 9
0
TEST(WebKit2, SpacebarScrolling)
{
    WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
    PlatformWebView webView(context.get());

    WKPageLoaderClient loaderClient;
    memset(&loaderClient, 0, sizeof(loaderClient));
    
    loaderClient.version = 0;
    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
    WKPageSetPageLoaderClient(webView.page(), &loaderClient);

    WKPageUIClient uiClient;
    memset(&uiClient, 0, sizeof(uiClient));

    uiClient.didNotHandleKeyEvent = didNotHandleKeyEventCallback;
    WKPageSetPageUIClient(webView.page(), &uiClient);

    WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("spacebar-scrolling", "html"));
    WKPageLoadURL(webView.page(), url.get());
    Util::run(&didFinishLoad);

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "false"));

    webView.simulateSpacebarKeyPress();

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "false"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));

    // On Mac, a key down event represents both a raw key down and a key press. On Windows, a key
    // down event only represents a raw key down. We expect the key press to be handled (because it
    // inserts text into the text field). But the raw key down should not be handled.
#if PLATFORM(MAC)
    TEST_ASSERT(!didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    TEST_ASSERT(didNotHandleKeyDownEvent);
#endif

    TEST_ASSERT(runJSTest(webView.page(), "blurTextField()", "undefined"));

    didNotHandleKeyDownEvent = false;
    webView.simulateSpacebarKeyPress();

    TEST_ASSERT(runJSTest(webView.page(), "isDocumentScrolled()", "true"));
    TEST_ASSERT(runJSTest(webView.page(), "textFieldContainsSpace()", "true"));
#if PLATFORM(MAC)
    TEST_ASSERT(!didNotHandleKeyDownEvent);
#elif PLATFORM(WIN)
    TEST_ASSERT(didNotHandleKeyDownEvent);
#endif
}
Esempio n. 10
0
static int test_override(void)
{
	struct charge_port_info charge;

	/* Initialize table to no charge */
	initialize_charge_table(0, 5000, 1000);

	/*
	 * Set a low-priority supplier on p0 and high-priority on p1, then
	 * verify that p1 is selected.
	 */
	charge.current = 500;
	charge.voltage = 5000;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge_manager_update(CHARGE_SUPPLIER_TEST1, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 500);

	/* Set override to p0 and verify p0 is selected */
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);

	/* Remove override and verify p1 is again selected */
	charge_manager_set_override(OVERRIDE_OFF);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);

	/*
	 * Set override again to p0, but set p0 charge to 0, and verify p1
	 * is again selected.
	 */
	charge.current = 0;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);

	/* Set non-zero charge on port 0 and verify override was auto-removed */
	charge.current = 250;
	charge_manager_update(CHARGE_SUPPLIER_TEST5, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);

	/*
	 * Verify current limit is still selected according to supplier
	 * priority on the override port.
	 */
	charge.current = 300;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 300);
	charge.current = 100;
	charge_manager_update(CHARGE_SUPPLIER_TEST1, 0, &charge);
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 100);

	/* Set override to "don't charge", then verify we're not charging */
	charge_manager_set_override(OVERRIDE_DONT_CHARGE);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
	TEST_ASSERT(active_charge_limit == 0);

	/* Update a charge supplier, verify that we still aren't charging */
	charge.current = 200;
	charge_manager_update(CHARGE_SUPPLIER_TEST1, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
	TEST_ASSERT(active_charge_limit == 0);

	/* Turn override off, verify that we go back to the correct charge */
	charge_manager_set_override(OVERRIDE_OFF);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 500);

	return EC_SUCCESS;
}
Esempio n. 11
0
static int test_dual_role(void)
{
	struct charge_port_info charge;

	/* Initialize table to no charge. */
	initialize_charge_table(0, 5000, 1000);

	/*
	 * Mark P0 as dual-role and set a charge. Verify that we don't charge
	 * from the port.
	 */
	set_charger_role(0, DUAL_ROLE_CHARGER);
	charge.current = 500;
	charge.voltage = 5000;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
	TEST_ASSERT(active_charge_limit == 0);

	/* Mark P0 as the override port, verify that we now charge. */
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 500);

	/* Remove override and verify we go back to not charging */
	charge_manager_set_override(OVERRIDE_OFF);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);
	TEST_ASSERT(active_charge_limit == 0);

	/* Mark P0 as the override port, verify that we again charge. */
	charge_manager_set_override(0);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 500);

	/* Insert a dedicated charger and verify override is removed */
	charge.current = 400;
	charge_manager_update(CHARGE_SUPPLIER_TEST6, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 400);

	/*
	 * Verify the port is handled normally if the dual-role source is
	 * unplugged and replaced with a dedicated source.
	 */
	set_charger_role(0, DEDICATED_CHARGER);
	charge.current = 0;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge.current = 500;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 500);

	/*
	 * Verify that we charge from the dedicated port if a dual-role
	 * source is also attached.
	 */
	set_charger_role(0, DUAL_ROLE_CHARGER);
	charge.current = 0;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge.current = 500;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 0, &charge);
	charge.current = 200;
	charge_manager_update(CHARGE_SUPPLIER_TEST6, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 200);

	return EC_SUCCESS;
}
Esempio n. 12
0
static int test_new_power_request(void)
{
	struct charge_port_info charge;

	/* Initialize table to no charge */
	initialize_charge_table(0, 5000, 5000);
	/* Clear power requests, and verify they are zero'd */
	clear_new_power_requests();
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 0);
	TEST_ASSERT(new_power_request[1] == 0);

	/* Charge from port 1 and verify NPR on port 1 only */
	charge.current = 1000;
	charge.voltage = 5000;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 0);
	TEST_ASSERT(new_power_request[1] == 1);
	clear_new_power_requests();

	/* Reduce port 1 through ceil and verify no NPR */
	charge_manager_set_ceil(1, 500);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 0);
	TEST_ASSERT(new_power_request[1] == 0);
	clear_new_power_requests();

	/* Change port 1 voltage and verify NPR on port 1 */
	charge.voltage = 4000;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 0);
	TEST_ASSERT(new_power_request[1] == 1);
	clear_new_power_requests();

	/* Add low-priority source and verify no NPRs */
	charge_manager_update(CHARGE_SUPPLIER_TEST6, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 0);
	TEST_ASSERT(new_power_request[1] == 0);
	clear_new_power_requests();

	/*
	 * Add higher-priority source and verify NPR on both ports,
	 * since we're switching charge ports.
	 */
	charge_manager_update(CHARGE_SUPPLIER_TEST1, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(new_power_request[0] == 1);
	TEST_ASSERT(new_power_request[1] == 1);
	clear_new_power_requests();

	return EC_SUCCESS;
}
Esempio n. 13
0
static int test_priority(void)
{
	struct charge_port_info charge;

	/* Initialize table to no charge */
	initialize_charge_table(0, 5000, 5000);
	TEST_ASSERT(active_charge_port == CHARGE_PORT_NONE);

	/*
	 * Set a 1A charge via a high-priority supplier and a 2A charge via
	 * a low-priority supplier, and verify the HP supplier is chosen.
	 */
	charge.current = 2000;
	charge.voltage = 5000;
	charge_manager_update(CHARGE_SUPPLIER_TEST6, 0, &charge);
	charge.current = 1000;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 1000);

	/*
	 * Set a higher charge on a LP supplier and verify we still use the
	 * lower charge.
	 */
	charge.current = 1500;
	charge_manager_update(CHARGE_SUPPLIER_TEST7, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 1000);

	/*
	 * Zero our HP charge and verify fallback to next highest priority,
	 * which happens to be a different port.
	 */
	charge.current = 0;
	charge_manager_update(CHARGE_SUPPLIER_TEST2, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 2000);

	/* Add a charge at equal priority and verify highest charge selected */
	charge.current = 2500;
	charge_manager_update(CHARGE_SUPPLIER_TEST5, 0, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 0);
	TEST_ASSERT(active_charge_limit == 2500);

	charge.current = 3000;
	charge_manager_update(CHARGE_SUPPLIER_TEST6, 1, &charge);
	wait_for_charge_manager_refresh();
	TEST_ASSERT(active_charge_port == 1);
	TEST_ASSERT(active_charge_limit == 3000);

	return EC_SUCCESS;
}
Esempio n. 14
0
int main(int argc, char *argv[])
{
	struct vmx_pages *vmx_pages = NULL;
	vm_vaddr_t vmx_pages_gva = 0;

	struct kvm_regs regs1, regs2;
	struct kvm_vm *vm;
	struct kvm_run *run;
	struct kvm_x86_state *state;
	int stage;

	struct kvm_cpuid_entry2 *entry = kvm_get_supported_cpuid_entry(1);

	/* Create VM */
	vm = vm_create_default(VCPU_ID, 0, guest_code);
	vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
	run = vcpu_state(vm, VCPU_ID);

	vcpu_regs_get(vm, VCPU_ID, &regs1);

	if (kvm_check_cap(KVM_CAP_NESTED_STATE)) {
		vmx_pages = vcpu_alloc_vmx(vm, &vmx_pages_gva);
		vcpu_args_set(vm, VCPU_ID, 1, vmx_pages_gva);
	} else {
		printf("will skip nested state checks\n");
		vcpu_args_set(vm, VCPU_ID, 1, 0);
	}

	for (stage = 1;; stage++) {
		_vcpu_run(vm, VCPU_ID);
		TEST_ASSERT(run->exit_reason == KVM_EXIT_IO,
			    "Unexpected exit reason: %u (%s),\n",
			    run->exit_reason,
			    exit_reason_str(run->exit_reason));

		memset(&regs1, 0, sizeof(regs1));
		vcpu_regs_get(vm, VCPU_ID, &regs1);
		switch (run->io.port) {
		case GUEST_PORT_ABORT:
			TEST_ASSERT(false, "%s at %s:%d", (const char *) regs1.rdi,
				    __FILE__, regs1.rsi);
			/* NOT REACHED */
		case GUEST_PORT_SYNC:
			break;
		case GUEST_PORT_DONE:
			goto done;
		default:
			TEST_ASSERT(false, "Unknown port 0x%x.", run->io.port);
		}

		/* PORT_SYNC is handled here.  */
		TEST_ASSERT(!strcmp((const char *)regs1.rdi, "hello") &&
			    regs1.rsi == stage, "Unexpected register values vmexit #%lx, got %lx",
			    stage, (ulong) regs1.rsi);

		state = vcpu_save_state(vm, VCPU_ID);
		kvm_vm_release(vm);

		/* Restore state in a new VM.  */
		kvm_vm_restart(vm, O_RDWR);
		vm_vcpu_add(vm, VCPU_ID, 0, 0);
		vcpu_set_cpuid(vm, VCPU_ID, kvm_get_supported_cpuid());
		vcpu_load_state(vm, VCPU_ID, state);
		run = vcpu_state(vm, VCPU_ID);
		free(state);

		memset(&regs2, 0, sizeof(regs2));
		vcpu_regs_get(vm, VCPU_ID, &regs2);
		TEST_ASSERT(!memcmp(&regs1, &regs2, sizeof(regs2)),
			    "Unexpected register values after vcpu_load_state; rdi: %lx rsi: %lx",
			    (ulong) regs2.rdi, (ulong) regs2.rsi);
	}

done:
	kvm_vm_free(vm);
}
Esempio n. 15
0
static void didCommitLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
{
    WKRetainPtr<WKStringRef> wkMIME(AdoptWK, WKFrameCopyMIMEType(frame));
    TEST_ASSERT(WKStringIsEqualToUTF8CString(wkMIME.get(), "image/png"));
}
Esempio n. 16
0
/**
 * Unit test's main function.
 */
int
main ()
{
  /* int ecma_date_day (time)*/

  TEST_ASSERT (ecma_date_day (0) == 0);
  TEST_ASSERT (ecma_date_day (MS_PER_DAY) == 1);

  /* ecma_number_t ecma_date_time_within_day (time) */

  TEST_ASSERT (ecma_date_time_within_day (0) == 0);
  TEST_ASSERT (ecma_date_time_within_day (42) == 42);
  TEST_ASSERT (ecma_date_time_within_day (42.51) == 42.51);
  TEST_ASSERT (ecma_date_time_within_day (MS_PER_DAY + 42) == 42);

  /* int ecma_date_year_from_time (time) */

  TEST_ASSERT (ecma_date_year_from_time (0) == 1970);
  TEST_ASSERT (ecma_date_year_from_time (0) == 1970);
  TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY) == 1970);
  TEST_ASSERT (ecma_date_year_from_time ((MS_PER_DAY) * (ecma_number_t) 365 - 1) == 1970);
  TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) 365) == 1971);
  TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) (365 * (2015 - 1970)))
                == 2014);
  TEST_ASSERT (ecma_date_year_from_time (MS_PER_DAY * (ecma_number_t) (365.25 * (2015 - 1970)))
                == 2015);
  TEST_ASSERT (ecma_date_year_from_time (-MS_PER_YEAR) == 1969);
  TEST_ASSERT (ecma_date_year_from_time (-1970 * MS_PER_YEAR) == 1);
  TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 1) == -1);
  TEST_ASSERT (ecma_date_year_from_time (START_OF_GREGORIAN_CALENDAR - 3 * MS_PER_YEAR) == -3);

  /* int ecma_date_month_from_time  (time) */

  TEST_ASSERT (ecma_date_month_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_month_from_time (0) == 0);
  TEST_ASSERT (ecma_date_month_from_time (-MS_PER_DAY) == 11);
  TEST_ASSERT (ecma_date_month_from_time (31 * MS_PER_DAY) == 1);

  /* int ecma_date_date_from_time  (time) */

  TEST_ASSERT (ecma_date_date_from_time (START_OF_GREGORIAN_CALENDAR) == 1);
  TEST_ASSERT (ecma_date_date_from_time (0) == 1);
  TEST_ASSERT (ecma_date_date_from_time (-MS_PER_DAY) == 31);
  TEST_ASSERT (ecma_date_date_from_time (31 * MS_PER_DAY) == 1);

  /* int ecma_date_week_day (ecma_number_t time) */

  /* FIXME: Implement */

  /* ecma_number_t ecma_date_utc (time) */

  /* FIXME: Implement */

  /* ecma_number_t ecma_date_hour_from_time (time) */

  TEST_ASSERT (ecma_date_hour_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_hour_from_time (0) == 0);
  TEST_ASSERT (ecma_date_hour_from_time (-MS_PER_DAY) == 0);
  TEST_ASSERT (ecma_date_hour_from_time (-1) == 23);

  /* ecma_number_t ecma_date_min_from_time (time) */

  TEST_ASSERT (ecma_date_min_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_min_from_time (0) == 0);
  TEST_ASSERT (ecma_date_min_from_time (-MS_PER_DAY) == 0);
  TEST_ASSERT (ecma_date_min_from_time (-1) == 59);

  /* ecma_number_t ecma_date_sec_from_time (time) */

  TEST_ASSERT (ecma_date_sec_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_sec_from_time (0) == 0);
  TEST_ASSERT (ecma_date_sec_from_time (-MS_PER_DAY) == 0);
  TEST_ASSERT (ecma_date_sec_from_time (-1) == 59);

  /* ecma_number_t ecma_date_ms_from_time (time) */

  TEST_ASSERT (ecma_date_ms_from_time (START_OF_GREGORIAN_CALENDAR) == 0);
  TEST_ASSERT (ecma_date_ms_from_time (0) == 0);
  TEST_ASSERT (ecma_date_ms_from_time (-MS_PER_DAY) == 0);
  TEST_ASSERT (ecma_date_ms_from_time (-1) == 999);

  /* ecma_number_t ecma_date_make_time (hour, min, sec, ms) */

  /* FIXME: Implement */

  /* ecma_number_t ecma_date_make_day (year, month, date) */

  TEST_ASSERT (ecma_date_make_day (1970, 0, 1) == 0);
  TEST_ASSERT (ecma_date_make_day (1970, -1, 1) == -31);
  TEST_ASSERT (ecma_date_make_day (1970, 0, 2.5) == 1);
  TEST_ASSERT (ecma_date_make_day (1970, 1, 35) == 65);
  TEST_ASSERT (ecma_date_make_day (1970, 13, 35) == 430);
  TEST_ASSERT (ecma_date_make_day (2016, 2, 1) == 16861);
  TEST_ASSERT (ecma_date_make_day (2016, 8, 31) == 17075);
  TEST_ASSERT (ecma_date_make_day (2016, 9, 1) == 17075);

  /* ecma_number_t ecma_date_make_date (day, time) */

  /* FIXME: Implement */

  /* ecma_number_t ecma_date_time_clip (year) */

  /* FIXME: Implement */

  return 0;
} /* main */
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( DomainTransporter, Boundary )
{
    typedef Tpetra::Vector<double,int,long> VectorType;
    typedef Tpetra::CrsMatrix<double,int,long> MatrixType;
    typedef MCLS::MatrixTraits<VectorType,MatrixType> MT;
    typedef MCLS::AdjointHistory<long> HistoryType;
    typedef std::mt19937 rng_type;
    typedef MCLS::AdjointTally<VectorType> TallyType;
    typedef MCLS::AlmostOptimalDomain<VectorType,MatrixType,rng_type,TallyType>
	DomainType;

    Teuchos::RCP<const Teuchos::Comm<int> > comm = 
	Teuchos::DefaultComm<int>::getComm();
    int comm_size = comm->getSize();
    int comm_rank = comm->getRank();

    // This test really needs a decomposed domain such that we can check
    // hitting the local domain boundary.
    if ( comm_size > 1 )
    {
	int local_num_rows = 10;
	int global_num_rows = local_num_rows*comm_size;
	Teuchos::RCP<const Tpetra::Map<int,long> > map = 
	    Tpetra::createUniformContigMap<int,long>( global_num_rows, comm );

	// Build the linear operator and solution vector.
	Teuchos::RCP<MatrixType> A = Tpetra::createCrsMatrix<double,int,long>( map );
	Teuchos::Array<long> global_columns( 3 );
	Teuchos::Array<double> values( 3 );

	global_columns[0] = 0;
	global_columns[1] = 1;
	global_columns[2] = 2;
	values[0] = 1.0/comm_size;
	values[1] = -0.499/comm_size;
	values[2] = -0.499/comm_size;
	A->insertGlobalValues( 0, global_columns(), values() );
	for ( int i = 1; i < global_num_rows-1; ++i )
	{
	    global_columns[0] = i-1;
	    global_columns[1] = i;
	    global_columns[2] = i+1;
	    values[0] = -0.499/comm_size;
	    values[1] = 1.0/comm_size;
	    values[2] = -0.499/comm_size;
	    A->insertGlobalValues( i, global_columns(), values() );
	}
	global_columns[0] = global_num_rows-3;
	global_columns[1] = global_num_rows-2;
	global_columns[2] = global_num_rows-1;
	values[0] = -0.499/comm_size;
	values[1] = -0.499/comm_size;
	values[2] = 1.0/comm_size;
	A->insertGlobalValues( global_num_rows-1, global_columns(), values() );
	A->fillComplete();

	Teuchos::RCP<VectorType> x = MT::cloneVectorFromMatrixRows( *A );
        Teuchos::RCP<MatrixType> A_T = MT::copyTranspose(*A);

	// Build the adjoint domain.
	Teuchos::ParameterList plist;
	plist.set<int>( "History Length", 10000 );
	Teuchos::RCP<DomainType> domain = 
            Teuchos::rcp( new DomainType( A_T, x, plist ) );
	Teuchos::RCP<MCLS::PRNG<rng_type> > rng = Teuchos::rcp(
	    new MCLS::PRNG<rng_type>( comm->getRank() ) );
	domain->setRNG( rng );

	// Build the domain transporter.
	MCLS::DomainTransporter<DomainType> transporter( domain );

	// Transport histories through the domain until they hit a boundary.
	double weight = 3.0; 
	for ( int i = 0; i < global_num_rows-1; ++i )
	{
	    if ( i >= local_num_rows*comm_rank && i < local_num_rows*(comm_rank+1) )
	    {
		HistoryType history( i, i, weight );
		history.live();
		transporter.transport( history );

		TEST_ASSERT( history.event() ==  MCLS::Event::BOUNDARY );
		TEST_ASSERT( !history.alive() );
	    }
	}
    }
}
Esempio n. 18
0
void rootTask (long a0, long a1, long a2, long a3, long a4,
	       long a5, long a6, long a7, long a8, long a9)
{
    WIND_TCB *pTcb;

    TEST_START(0);

    pTcb = taskTcb(taskIdSelf());
    TEST_ASSERT(pTcb != NULL);

    bsemid = semBCreate(0xffffffff,0);
    TEST_ASSERT(bsemid == 0 && errno == S_semLib_INVALID_QUEUE_TYPE);

    bsemid = semBCreate(SEM_Q_PRIORITY,0);
    TEST_ASSERT(bsemid != 0);

    mutexid = semMCreate(0xffffffff);
    TEST_ASSERT(mutexid == 0 && errno == S_semLib_INVALID_QUEUE_TYPE);

    mutexid = semMCreate(SEM_Q_PRIORITY|SEM_DELETE_SAFE|SEM_INVERSION_SAFE);
    TEST_ASSERT(mutexid != 0);

    taskSpawn("Test1",
	      20,		/* low-pri */
	      0,
	      32768,
	      sem1Task,
	      taskIdSelf(),0,0,0,0,0,0,0,0,0);

    taskSpawn("Test2",
	      10,		/* intermediate-pri */
	      0,
	      32768,
	      sem2Task,
	      taskIdSelf(),0,0,0,0,0,0,0,0,0);

    /* This runs at high-pri */

    TEST_MARK();

    TEST_ASSERT_OK(semTake(bsemid,WAIT_FOREVER));

    TEST_MARK();

    TEST_ASSERT_OK(taskSuspend(0));

    TEST_MARK();

    TEST_ASSERT_OK(semTake(mutexid,WAIT_FOREVER));

    TEST_MARK();

    TEST_ASSERT_OK(semGive(mutexid));

    TEST_MARK();

    TEST_ASSERT(taskIsReady(taskNameToId("Test2")));

    TEST_ASSERT(!taskIsSuspended(taskNameToId("Test2")));

    TEST_ASSERT_OK(taskDelay(1));

    TEST_MARK();

    TEST_CHECK_SEQUENCE(SEQ("root",1),
			SEQ("Test2",1),
			SEQ("root",1),
			SEQ("Test2",1),
			SEQ("Test1",2),
			SEQ("Test2",1),
			SEQ("root",1),
			SEQ("Test1",1),
			SEQ("root",2),
			SEQ("Test2",1),
			SEQ("root",1),
			END_SEQ);
    TEST_FINISH();
}
Esempio n. 19
0
static int
test_stats_entry_setup_from_add(void)
{
    of_flow_add_t *add;
    of_flow_stats_entry_t *entry;
    of_match_t m1, m2;
    of_list_action_t *list;
    of_list_action_t list_out;

    TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
    TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);

    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
    TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);

    TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, NULL) == 0);
    TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
    TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);

    of_flow_add_delete(add);
    of_flow_stats_entry_delete(entry);

    /* @todo check action lists agree */

    /* Same with an external action list */

    TEST_ASSERT((add = of_flow_add_new(OF_VERSION_1_0)) != NULL);
    TEST_ASSERT((entry = of_flow_stats_entry_new(OF_VERSION_1_0)) != NULL);

    TEST_ASSERT(of_flow_add_OF_VERSION_1_0_populate(add, 1) != 0);
    TEST_ASSERT(of_flow_add_match_get(add, &m1) == 0);

    list = of_list_action_new(OF_VERSION_1_0);
    TEST_ASSERT(list != NULL);
    TEST_ASSERT(of_list_action_OF_VERSION_1_0_populate(list, 1) != 0);

    /* Verify matches agree */
    TEST_ASSERT(of_flow_stats_entry_setup_from_flow_add(entry, add, list) == 0);
    TEST_ASSERT(of_flow_stats_entry_match_get(entry, &m2) == 0);
    TEST_ASSERT(memcmp(&m1, &m2, sizeof(m1)) == 0);

    of_list_action_init(&list_out, OF_VERSION_1_0, 0, 1);
    of_flow_stats_entry_actions_bind(entry, &list_out);

    /* Verify lists agree */
    TEST_ASSERT(list->length == list_out.length);
    TEST_ASSERT(memcmp(WBUF_BUF(list->wire_object.wbuf),
                       WBUF_BUF(list_out.wire_object.wbuf),
                       list->length));

    of_flow_add_delete(add);
    of_list_action_delete(list);
    of_flow_stats_entry_delete(entry);

    return TEST_PASS;
}
Esempio n. 20
0
int
main (void)
{
  TEST_INIT ();

  const lit_utf8_byte_t *ptrs[test_sub_iters];
  ecma_number_t numbers[test_sub_iters];
  lit_utf8_byte_t strings[test_sub_iters][max_characters_in_string + 1];
  lit_utf8_size_t lengths[test_sub_iters];

  jmem_init ();

  for (uint32_t i = 0; i < test_iters; i++)
  {
    memset (numbers, 0, sizeof (ecma_number_t) * test_sub_iters);
    memset (lengths, 0, sizeof (lit_utf8_size_t) * test_sub_iters);
    memset (ptrs, 0, sizeof (lit_utf8_byte_t *) * test_sub_iters);

    for (uint32_t j = 0; j < test_sub_iters; j++)
    {
      int type = rand () % 3;
      if (type == 0)
      {
        lengths[j] = (lit_utf8_size_t) (rand () % max_characters_in_string + 1);
        generate_string (strings[j], lengths[j]);
        ecma_find_or_create_literal_string (strings[j], lengths[j]);
        strings[j][lengths[j]] = '\0';
        ptrs[j] = strings[j];
        TEST_ASSERT (ptrs[j]);
      }
      else if (type == 1)
      {
        lit_magic_string_id_t msi = (lit_magic_string_id_t) (rand () % LIT_NON_INTERNAL_MAGIC_STRING__COUNT);
        ptrs[j] = lit_get_magic_string_utf8 (msi);
        TEST_ASSERT (ptrs[j]);
        lengths[j] = (lit_utf8_size_t) lit_zt_utf8_string_size (ptrs[j]);
        ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
      }
      else
      {
        ecma_number_t num = generate_number ();
        lengths[j] = ecma_number_to_utf8_string (num, strings[j], max_characters_in_string);
        ecma_find_or_create_literal_number (num);
      }
    }

    /* Add empty string. */
    ecma_find_or_create_literal_string (NULL, 0);

    for (uint32_t j = 0; j < test_sub_iters; j++)
    {
      jmem_cpointer_t lit1;
      jmem_cpointer_t lit2;
      if (ptrs[j])
      {
        lit1 = ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
        lit2 = ecma_find_or_create_literal_string (ptrs[j], lengths[j]);
        TEST_ASSERT (lit1 == lit2);
      }
      else
      {
        lit1 = ecma_find_or_create_literal_number (numbers[j]);
        lit2 = ecma_find_or_create_literal_number (numbers[j]);
        TEST_ASSERT (lit1 == lit2);
      }
      TEST_ASSERT (lit1);
      TEST_ASSERT (lit2);
      TEST_ASSERT (lit1 == lit2);
    }

    /* Check empty string exists. */
    TEST_ASSERT (ecma_find_or_create_literal_string (NULL, 0) != JMEM_CP_NULL);
  }

  ecma_finalize_lit_storage ();
  jmem_finalize ();
  return 0;
} /* main */
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( DomainTransporter, Boundary )
{
    typedef Epetra_Vector VectorType;
    typedef Epetra_RowMatrix MatrixType;
    typedef MCLS::MatrixTraits<VectorType,MatrixType> MT;
    typedef MCLS::AdjointHistory<int> HistoryType;
    typedef std::mt19937 rng_type;
    typedef MCLS::AdjointDomain<VectorType,MatrixType,rng_type> DomainType;

    Teuchos::RCP<const Teuchos::Comm<int> > comm = 
	Teuchos::DefaultComm<int>::getComm();
    Teuchos::RCP<Epetra_Comm> epetra_comm = getEpetraComm( comm );
    int comm_size = comm->getSize();
    int comm_rank = comm->getRank();

    // This test really needs a decomposed domain such that we can check
    // hitting the local domain boundary.
    if ( comm_size > 1 )
    {
	int local_num_rows = 10;
	int global_num_rows = local_num_rows*comm_size;
	Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(
	    new Epetra_Map( global_num_rows, 0, *epetra_comm ) );

	// Build the linear operator and solution vector. This operator will
	// be assymetric so we quickly move the histories out of the domain
	// before they hit the low weight cutoff.
	Teuchos::RCP<Epetra_CrsMatrix> A = 	
	    Teuchos::rcp( new Epetra_CrsMatrix( Copy, *map, 0 ) );
	Teuchos::Array<int> global_columns( 3 );
	Teuchos::Array<double> values( 3 );

	global_columns[0] = 0;
	global_columns[1] = 1;
	global_columns[2] = 2;
	values[0] = 1.0;
	values[1] = 0.49;
	values[2] = 0.49;
	A->InsertGlobalValues( 0, global_columns.size(),
			       &values[0], &global_columns[0] );
	for ( int i = 1; i < global_num_rows-1; ++i )
	{
	    global_columns[0] = i-1;
	    global_columns[1] = i;
	    global_columns[2] = i+1;
	    values[0] = 0.49;
	    values[1] = 1.0;
	    values[2] = 0.49;
	    A->InsertGlobalValues( i, global_columns.size(),
				   &values[0], &global_columns[0] );
	}
	global_columns[0] = global_num_rows-3;
	global_columns[1] = global_num_rows-2;
	global_columns[2] = global_num_rows-1;
	values[0] = 0.49;
	values[1] = 0.49;
	values[2] = 1.0;
	A->InsertGlobalValues( global_num_rows-1, global_columns().size(), 
			       &values[0], &global_columns[0] );
	A->FillComplete();

	Teuchos::RCP<MatrixType> B = MT::copyTranspose(*A);
	Teuchos::RCP<VectorType> x = MT::cloneVectorFromMatrixRows( *A );

	// Build the adjoint domain.
	Teuchos::ParameterList plist;
	plist.set<int>( "Overlap Size", 2 );
	Teuchos::RCP<DomainType> domain = Teuchos::rcp( new DomainType( B, x, plist ) );
	Teuchos::RCP<MCLS::PRNG<rng_type> > rng = Teuchos::rcp(
	    new MCLS::PRNG<rng_type>( comm->getRank() ) );
	domain->setRNG( rng );

	// Build the domain transporter.
	MCLS::DomainTransporter<DomainType> transporter( domain, plist );
	domain->setCutoff( 1.0e-12 );

	// Transport histories through the domain until they hit a boundary.
	double weight = 3.0; 
	for ( int i = 0; i < global_num_rows-1; ++i )
	{
	    if ( comm_rank == comm_size - 1 )
	    {
		if ( i >= local_num_rows*comm_rank && i < local_num_rows*(comm_rank+1) )
		{
		    HistoryType history( i, i, weight );
		    history.live();
		    transporter.transport( history );

		    TEST_ASSERT( history.event() == 
				 MCLS::Event::BOUNDARY || MCLS::Event::CUTOFF );
		    TEST_ASSERT( !history.alive() );
		}
	    }
	    else
	    {
		if ( i >= local_num_rows*comm_rank && i < 2+local_num_rows*(comm_rank+1) )
		{
		    HistoryType history( i, i, weight );
		    history.live();
		    transporter.transport( history );

		    TEST_ASSERT( history.event() ==
				 MCLS::Event::BOUNDARY || MCLS::Event::CUTOFF );
		    TEST_ASSERT( !history.alive() );
		}
	    }
	}
    }
}
Esempio n. 22
0
int main(int n, char **p)
{
	Step::RefPtr<ifc2x3::ExpressDataSet> eds ;
	try
	{
		std::cout << "Creating ExpressDataSet" << std::endl;
		eds = new ifc2x3::ExpressDataSet;
	}
	catch (const std::exception& e)
	{
		TEST_FAILURE((std::string("Exception : ") + e.what()).c_str());
	}

	TEST_VALIDITY(eds);

	Step::RefPtr<ifc2x3::IfcCartesianTransformationOperator3D> CTOperator3D = eds->createIfcCartesianTransformationOperator3D();
	TEST_VALIDITY(CTOperator3D);

///////////////////////////////////////////////////////////////////////////////////
	ifc2x3::List_IfcDirection_3_3 ListIfcDirection1 = CTOperator3D->getU();
	LOG_DEBUG("Axis1, Axis2 and Axis3 not exist" << std::endl);

	TEST_ASSERT(ListIfcDirection1[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection1[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection1[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection1[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection1[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection1[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection1[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection1[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection1[2]->getDirectionRatios()[2]==1.0);
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

	Step::RefPtr< ifc2x3::IfcDirection > Axis1 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal1;
	ListReal1.push_back(1.0);
	ListReal1.push_back(0.0);
	ListReal1.push_back(0.0);
	Axis1->setDirectionRatios(ListReal1);
	
	CTOperator3D->setAxis1(Axis1);
	ifc2x3::List_IfcDirection_3_3 ListIfcDirection2 = CTOperator3D->getU();
	
	LOG_DEBUG("Axis1 [1.0;0.0] and Axis2 not exist" << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection2[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection2[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection2[0]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection2[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection2[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection2[1]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection2[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection2[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection2[2]->getDirectionRatios()[2] << "]" << std::endl);

	TEST_ASSERT(ListIfcDirection2[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection2[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection2[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection2[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection2[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection2[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection2[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection2[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection2[2]->getDirectionRatios()[2]==1.0);

///////////////////////////////////////////////////////////////////////////////////

	Step::RefPtr< ifc2x3::IfcDirection > Axis2 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal2;
	ListReal2.push_back(0.0);
	ListReal2.push_back(1.0);
	ListReal2.push_back(0.0);
	Axis2->setDirectionRatios(ListReal2);

	CTOperator3D->setAxis2(Axis2);
	ifc2x3::List_IfcDirection_3_3 ListIfcDirection3 = CTOperator3D->getU();

	LOG_DEBUG("Axis1 [1.0;0.0;0.0] and Axis2[0.0;1.0;0.0]" << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection3[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection3[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection3[0]->getDirectionRatios()[2]<< "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection3[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection3[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection3[1]->getDirectionRatios()[2]<< "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection3[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection3[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection3[2]->getDirectionRatios()[2]<< "]" << std::endl);

	TEST_ASSERT(ListIfcDirection3[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection3[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection3[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection3[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection3[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection3[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection3[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection3[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection3[2]->getDirectionRatios()[2]==1.0);

///////////////////////////////////////////////////////////////////////////////////

	Step::RefPtr< ifc2x3::IfcDirection > Axis3 = eds->createIfcDirection();
	ifc2x3::List_Real_2_3 ListReal3;
	ListReal3.push_back(0.0);
	ListReal3.push_back(0.0);
	ListReal3.push_back(1.0);
	Axis3->setDirectionRatios(ListReal3);

	CTOperator3D->setAxis3(Axis3);
	ifc2x3::List_IfcDirection_3_3 ListIfcDirection4 = CTOperator3D->getU();

	LOG_DEBUG("Axis1 [1.0;0.0;0.0], Axis2[0.0;1.0;0.0] And Axis3[0.0;0.0;1.0] " << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection4[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection4[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection4[0]->getDirectionRatios()[2]<< "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection4[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection4[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection4[1]->getDirectionRatios()[2]<< "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection4[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection4[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection4[2]->getDirectionRatios()[2]<< "]" << std::endl);

	TEST_ASSERT(ListIfcDirection4[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection4[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection4[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection4[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection4[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection4[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection4[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection4[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection4[2]->getDirectionRatios()[2]==1.0);

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

	ifc2x3::List_Real_2_3 ListReal4;
	ListReal4.push_back(0.0);
	ListReal4.push_back(0.0);
	ListReal4.push_back(1.0);
	Axis1->setDirectionRatios(ListReal4);
	CTOperator3D->setAxis1(Axis1);
	ifc2x3::List_IfcDirection_3_3 ListIfcDirection5 = CTOperator3D->getU();

	TEST_ASSERT(ListIfcDirection5.empty());
/*	
	LOG_DEBUG("Axis1 [0.0;0.0;1.0], Axis2[0.0;1.0;0.0] And Axis3[0.0;0.0;1.0]" << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection5[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection5[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection5[0]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection5[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection5[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection5[1]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection5[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection5[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection5[2]->getDirectionRatios()[2] << "]" << std::endl);

	TEST_ASSERT(ListIfcDirection5[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection5[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection5[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection5[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection5[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection5[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection5[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection5[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection5[2]->getDirectionRatios()[2]==1.0);
*/

///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

	ifc2x3::List_Real_2_3 ListReal5;
	ListReal5.push_back(2.0);
	ListReal5.push_back(0.0);
	ListReal5.push_back(0.0);
	Axis1->setDirectionRatios(ListReal5);
	CTOperator3D->setAxis1(Axis1);

	ifc2x3::List_Real_2_3 ListReal6;
	ListReal6.push_back(0.0);
	ListReal6.push_back(6.0);
	ListReal6.push_back(0.0);
	Axis2->setDirectionRatios(ListReal6);

	ifc2x3::List_Real_2_3 ListReal7;
	ListReal7.push_back(0.0);
	ListReal7.push_back(0.0);
	ListReal7.push_back(8.0);
	Axis3->setDirectionRatios(ListReal7);

	ifc2x3::List_IfcDirection_3_3 ListIfcDirection6 = CTOperator3D->getU();
		
	LOG_DEBUG("Axis1 [2.0;0.0;0.0], Axis2[0.0;6.0;0.0] And Axis3[0.0;0.0;8.0]" << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection6[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection6[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection6[0]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection6[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection6[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection6[1]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection6[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection6[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection6[2]->getDirectionRatios()[2] << "]" << std::endl);

	TEST_ASSERT(ListIfcDirection6[0]->getDirectionRatios()[0]==1.0);
	TEST_ASSERT(ListIfcDirection6[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection6[0]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection6[1]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection6[1]->getDirectionRatios()[1]==1.0);
	TEST_ASSERT(ListIfcDirection6[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection6[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection6[2]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection6[2]->getDirectionRatios()[2]==1.0);
	
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////

	ifc2x3::List_Real_2_3 ListReal8;
	ListReal8.push_back(0.0);
	ListReal8.push_back(0.0);
	ListReal8.push_back(5.0);
	Axis1->setDirectionRatios(ListReal8);
	CTOperator3D->setAxis1(Axis1);

	ifc2x3::List_Real_2_3 ListReal9;
	ListReal9.push_back(-5.0);
	ListReal9.push_back(0.0);
	ListReal9.push_back(0.0);
	Axis2->setDirectionRatios(ListReal9);

	ifc2x3::List_Real_2_3 ListReal10;
	ListReal10.push_back(0.0);
	ListReal10.push_back(-8.0);
	ListReal10.push_back(0.0);
	Axis3->setDirectionRatios(ListReal10);

	ifc2x3::List_IfcDirection_3_3 ListIfcDirection7 = CTOperator3D->getU();

	LOG_DEBUG("Axis1 [0.0;0.0;5.0], Axis2[-5.0;0.0;0.0] And Axis3[0.0;-8.0;0.0]" << std::endl);
	LOG_DEBUG("U[0] = ["<< ListIfcDirection7[0]->getDirectionRatios()[0] << " ; " << ListIfcDirection7[0]->getDirectionRatios()[1] << " ; " << ListIfcDirection7[0]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[1] = ["<< ListIfcDirection7[1]->getDirectionRatios()[0] << " ; " << ListIfcDirection7[1]->getDirectionRatios()[1] << " ; " << ListIfcDirection7[1]->getDirectionRatios()[2] << "]" << std::endl);
	LOG_DEBUG("U[2] = ["<< ListIfcDirection7[2]->getDirectionRatios()[0] << " ; " << ListIfcDirection7[2]->getDirectionRatios()[1] << " ; " << ListIfcDirection7[2]->getDirectionRatios()[2] << "]" << std::endl);

	TEST_ASSERT(ListIfcDirection7[0]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection7[0]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection7[0]->getDirectionRatios()[2]==1.0);
	TEST_ASSERT(ListIfcDirection7[1]->getDirectionRatios()[0]==-1.0);
	TEST_ASSERT(ListIfcDirection7[1]->getDirectionRatios()[1]==0.0);
	TEST_ASSERT(ListIfcDirection7[1]->getDirectionRatios()[2]==0.0);
	TEST_ASSERT(ListIfcDirection7[2]->getDirectionRatios()[0]==0.0);
	TEST_ASSERT(ListIfcDirection7[2]->getDirectionRatios()[1]==-1.0);
	TEST_ASSERT(ListIfcDirection7[2]->getDirectionRatios()[2]==0.0);

	std::cout << std::endl << "Failure : " << failure_results << " Success : " << success_results << std::endl;

	return failure_results;
}
//---------------------------------------------------------------------------//
TEUCHOS_UNIT_TEST( SourceTransporter, transport )
{
    typedef Epetra_Vector VectorType;
    typedef MCLS::VectorTraits<VectorType> VT;
    typedef Epetra_RowMatrix MatrixType;
    typedef MCLS::MatrixTraits<VectorType,MatrixType> MT;
    typedef MCLS::AdjointHistory<int> HistoryType;
    typedef std::mt19937 rng_type;
    typedef MCLS::AdjointDomain<VectorType,MatrixType,rng_type> DomainType;
    typedef MCLS::UniformAdjointSource<DomainType> SourceType;

    Teuchos::RCP<const Teuchos::Comm<int> > comm = 
	Teuchos::DefaultComm<int>::getComm();
    Teuchos::RCP<Epetra_Comm> epetra_comm = getEpetraComm( comm );
    int comm_size = comm->getSize();

    int local_num_rows = 10;
    int global_num_rows = local_num_rows*comm_size;
    Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(
	new Epetra_Map( global_num_rows, 0, *epetra_comm ) );

    // Build the linear system. This operator is symmetric with a spectral
    // radius less than 1.
    Teuchos::RCP<Epetra_CrsMatrix> A = 	
	Teuchos::rcp( new Epetra_CrsMatrix( Copy, *map, 0 ) );
    Teuchos::Array<int> global_columns( 3 );
    Teuchos::Array<double> values( 3 );
    global_columns[0] = 0;
    global_columns[1] = 1;
    global_columns[2] = 2;
    values[0] = 1.0/comm_size;
    values[1] = 0.12/comm_size;
    values[2] = 0.0/comm_size;
    A->InsertGlobalValues( 0, global_columns.size(), 
			   &values[0], &global_columns[0] );
    for ( int i = 1; i < global_num_rows-1; ++i )
    {
	global_columns[0] = i-1;
	global_columns[1] = i;
	global_columns[2] = i+1;
	values[0] = 0.12/comm_size;
	values[1] = 1.0/comm_size;
	values[2] = 0.12/comm_size;
	A->InsertGlobalValues( i, global_columns.size(), 
			       &values[0], &global_columns[0] );
    }
    global_columns[0] = global_num_rows-3;
    global_columns[1] = global_num_rows-2;
    global_columns[2] = global_num_rows-1;
    values[0] = 0.0/comm_size;
    values[1] = 0.12/comm_size;
    values[2] = 1.0/comm_size;
    A->InsertGlobalValues( global_num_rows-1, global_columns.size(), 
			   &values[0], &global_columns[0] );
    A->FillComplete();

    Teuchos::RCP<MatrixType> B = MT::copyTranspose(*A);
    Teuchos::RCP<VectorType> x = MT::cloneVectorFromMatrixRows( *B );
    VT::putScalar( *x, 0.0 );
    Teuchos::RCP<VectorType> b = MT::cloneVectorFromMatrixRows( *B );
    VT::putScalar( *b, -1.0 );

    // Build the adjoint domain.
    Teuchos::ParameterList plist;
    plist.set<int>( "Overlap Size", 2 );
    Teuchos::RCP<DomainType> domain = Teuchos::rcp( new DomainType( B, x, plist ) );
    Teuchos::RCP<MCLS::PRNG<rng_type> > rng = Teuchos::rcp(
	new MCLS::PRNG<rng_type>( comm->getRank() ) );
    domain->setRNG( rng );

    // History setup.
    HistoryType::setByteSize();

    // Create the adjoint source with a set number of histories.
    int mult = 100;
    double cutoff = 1.0e-6;
    plist.set<double>("Sample Ratio", mult);
    plist.set<double>("Weight Cutoff", cutoff);
    Teuchos::RCP<SourceType> source = Teuchos::rcp(
	new SourceType( b, domain, comm, 
			comm->getSize(), comm->getRank(), plist ) );
    source->setRNG( rng );
    source->buildSource();

    // Create the source transporter.
    plist.set<int>("MC Check Frequency", 10);
    double relative_cutoff = source->sourceWeight()*cutoff;
    MCLS::SourceTransporter<SourceType> source_transporter( 
	comm, domain, plist );
    source_transporter.assignSource( source, relative_cutoff );

    // Do transport.
    source_transporter.transport();
    domain->domainTally()->combineSetTallies( comm );

    // Check that we got a negative solution.
    Teuchos::ArrayRCP<const double> x_view = 
        VT::view( *x );
    Teuchos::ArrayRCP<const double>::const_iterator x_view_it;
    for ( x_view_it = x_view.begin(); x_view_it != x_view.end(); ++x_view_it )
    {
	TEST_ASSERT( *x_view_it < 0.0 );
    }
}
Esempio n. 24
0
// 
//------------------------------------------------------------------------------
void TestIncludeParser::TestEdgeCases() const
{
	FBuild fBuild; // needed fer CleanPath for relative dirs

	// include on last line
	{
		AStackString<> data( "#line 1 \"hello\"" );
		CIncludeParser parser;
		TEST_ASSERT( parser.ParseMSCL_Preprocessed( data.Get(), data.GetLength() ) );
		TEST_ASSERT( parser.GetIncludes().GetSize() == 1 );
		#ifdef DEBUG
			TEST_ASSERT( parser.GetNonUniqueCount() == 1 );
		#endif
	}

	// empty
	{
		AStackString<> data( "" );
		CIncludeParser parser;
		TEST_ASSERT( parser.ParseMSCL_Preprocessed( data.Get(), data.GetLength() ) );
		TEST_ASSERT( parser.GetIncludes().GetSize() == 0 );
		#ifdef DEBUG
			TEST_ASSERT( parser.GetNonUniqueCount() == 0 );
		#endif
	}

	// #pragma or #   pragma should be ignored
	{
		AStackString<> data( "#pragma message\"hello\"\n#   pragma message\"hello\"\n" );
		uint32_t dataLen = data.GetLength();
		CIncludeParser parser;
		TEST_ASSERT( parser.ParseGCC_Preprocessed( data.Get(), dataLen ) );
		TEST_ASSERT( parser.GetIncludes().GetSize() == 0 );
		#ifdef DEBUG
			TEST_ASSERT( parser.GetNonUniqueCount() == 0 );
		#endif
	}

    // "#line..." should both be found for clang (-fms-compat)
    {
		AStackString<> data( "#line 15 \"hello\"\n#line 2 \"hello\"" );
		uint32_t dataLen = data.GetLength();
		CIncludeParser parser;
		TEST_ASSERT( parser.ParseGCC_Preprocessed( data.Get(), dataLen ) );
		TEST_ASSERT( parser.GetIncludes().GetSize() == 1 );
		#ifdef DEBUG
			TEST_ASSERT( parser.GetNonUniqueCount() == 2 );
		#endif
    }
}
Esempio n. 25
0
int
testcase(gchar *msg, guint parse_flags, gint max_columns, guint32 flags, gchar *delimiters, gchar *quotes, gchar *null_value, gchar *first_value, ...)
{
  LogMessage *logmsg;
  LogColumnParser *p;
  gchar *expected_value;
  gint i;
  va_list va;
  NVTable *nvtable;

  const gchar *column_array[] =
  {
    "C1",
    "C2",
    "C3",
    "C4",
    "C5",
    "C6",
    "C7",
    "C8",
    "C9",
    "C10",
    "C11",
    "C12",
    "C13",
    "C14",
    "C15",
    "C16",
    "C17",
    "C18",
    "C19",
    "C20",
    "C21",
    "C22",
    "C23",
    "C24",
    "C25",
    "C26",
    "C27",
    "C28",
    "C29",
    "C30",
    NULL
  };
  gboolean success;

  if (max_columns != -1)
    {
      g_assert(max_columns < (sizeof(column_array) / sizeof(column_array[0])));

      column_array[max_columns] = NULL;
    }

  parse_options.flags = parse_flags;
  logmsg = log_msg_new(msg, strlen(msg), NULL, &parse_options);

  p = log_csv_parser_new();
  log_csv_parser_set_flags(p, flags);
  log_column_parser_set_columns(p, string_array_to_list(column_array));
  if (delimiters)
    log_csv_parser_set_delimiters(p, delimiters);
  if (quotes)
    log_csv_parser_set_quote_pairs(p, quotes);
  if (null_value)
    log_csv_parser_set_null_value(p, null_value);

  nvtable = nv_table_ref(logmsg->payload);
  success = log_parser_process(&p->super, logmsg, log_msg_get_value(logmsg, LM_V_MESSAGE, NULL));
  nv_table_unref(nvtable);

  if (success && !first_value)
    {
      fprintf(stderr, "unexpected match; msg=%s\n", msg);
      exit(1);
    }
  if (!success && first_value)
    {
      fprintf(stderr, "unexpected non-match; msg=%s\n", msg);
      exit(1);
    }
  log_pipe_unref(&p->super.super.super);

  va_start(va, first_value);
  expected_value = first_value;
  i = 0;
  while (expected_value && column_array[i])
    {
      const gchar *value;
      gssize value_len;

      value = log_msg_get_value(logmsg, log_msg_get_value_handle(column_array[i]), &value_len);

      if (expected_value && expected_value[0])
        {
          TEST_ASSERT(value && value[0], "expected value set, but no actual value");
          TEST_ASSERT(strlen(expected_value) == value_len, "value length doesn't match actual length");
          TEST_ASSERT(strncmp(value, expected_value, value_len) == 0, "value does not match expected value");
        }
      else
        {
          TEST_ASSERT(!(value && value[0]), "expected unset, but actual value present");
        }

      expected_value = va_arg(va, char *);
      i++;
    }

  log_msg_unref(logmsg);
  return 1;
}
Esempio n. 26
0
//Yup, nice comment
void test_TheFirstThingToTest(void)
{
    TEST_ASSERT(1);

    TEST_ASSERT_TRUE(1);
}
Esempio n. 27
0
//---------------------------------------------------------------------------
//
//      UVector32_API      Check for basic functionality of UVector32.
//
//---------------------------------------------------------------------------
void UVector32Test::UVector32_API() {

    UErrorCode  status = U_ZERO_ERROR;
    UVector32     *a;
    UVector32     *b;

    a = new UVector32(status);
    TEST_CHECK_STATUS(status);
    delete a;

    status = U_ZERO_ERROR;
    a = new UVector32(2000, status);
    TEST_CHECK_STATUS(status);
    delete a;

    //
    //  assign()
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    b->assign(*a, status);
    TEST_ASSERT(b->size() == 3);
    TEST_ASSERT(b->elementAti(1) == 20);
    TEST_CHECK_STATUS(status);
    delete a;
    delete b;

    //
    //  operator == and != and equals()
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    TEST_ASSERT(*b != *a);
    TEST_ASSERT(!(*b == *a));
    TEST_ASSERT(!b->equals(*a));
    b->assign(*a, status);
    TEST_ASSERT(*b == *a);
    TEST_ASSERT(!(*b != *a));
    TEST_ASSERT(b->equals(*a));
    b->addElement(666, status);
    TEST_ASSERT(*b != *a);
    TEST_ASSERT(!(*b == *a));
    TEST_ASSERT(!b->equals(*a));
    TEST_CHECK_STATUS(status);
    delete b;
    delete a;

    //
    //  addElement().   Covered by above tests.
    //

    //
    // setElementAt()
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    a->setElementAt(666, 1);
    TEST_ASSERT(a->elementAti(0) == 10);
    TEST_ASSERT(a->elementAti(1) == 666);
    TEST_ASSERT(a->size() == 3);
    TEST_CHECK_STATUS(status);
    delete a;

    //
    // insertElementAt()
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    a->insertElementAt(666, 1, status);
    TEST_ASSERT(a->elementAti(0) == 10);
    TEST_ASSERT(a->elementAti(1) == 666);
    TEST_ASSERT(a->elementAti(2) == 20);
    TEST_ASSERT(a->elementAti(3) == 30);
    TEST_ASSERT(a->size() == 4);
    TEST_CHECK_STATUS(status);
    delete a;

    //
    //  elementAti()    covered by above tests
    //

    //
    //  lastElementi
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    TEST_ASSERT(a->lastElementi() == 30);
    TEST_CHECK_STATUS(status);
    delete a;


    //
    //  indexOf
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    TEST_ASSERT(a->indexOf(30, 0) == 2);
    TEST_ASSERT(a->indexOf(40, 0) == -1);
    TEST_ASSERT(a->indexOf(10, 0) == 0);
    TEST_ASSERT(a->indexOf(10, 1) == -1);
    TEST_CHECK_STATUS(status);
    delete a;

    
    //
    //  contains
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    TEST_ASSERT(a->contains(10) == TRUE);
    TEST_ASSERT(a->contains(11) == FALSE);
    TEST_ASSERT(a->contains(20) == TRUE);
    TEST_ASSERT(a->contains(-10) == FALSE);
    TEST_CHECK_STATUS(status);
    delete a;


    //
    //  containsAll
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    TEST_ASSERT(a->containsAll(*b) == TRUE);
    b->addElement(2, status);
    TEST_ASSERT(a->containsAll(*b) == FALSE);
    b->setElementAt(10, 0);
    TEST_ASSERT(a->containsAll(*b) == TRUE);
    TEST_ASSERT(b->containsAll(*a) == FALSE);
    b->addElement(30, status);
    b->addElement(20, status);
    TEST_ASSERT(a->containsAll(*b) == TRUE);
    TEST_ASSERT(b->containsAll(*a) == TRUE);
    b->addElement(2, status);
    TEST_ASSERT(a->containsAll(*b) == FALSE);
    TEST_ASSERT(b->containsAll(*a) == TRUE);
    TEST_CHECK_STATUS(status);
    delete a;
    delete b;

    //
    //  removeAll
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    a->removeAll(*b);
    TEST_ASSERT(a->size() == 3);
    b->addElement(20, status);
    a->removeAll(*b);
    TEST_ASSERT(a->size() == 2);
    TEST_ASSERT(a->contains(10)==TRUE);
    TEST_ASSERT(a->contains(30)==TRUE);
    b->addElement(10, status);
    a->removeAll(*b);
    TEST_ASSERT(a->size() == 1);
    TEST_ASSERT(a->contains(30) == TRUE);
    TEST_CHECK_STATUS(status);
    delete a;
    delete b;

    //
    // retainAll
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    b->addElement(10, status);
    b->addElement(20, status);
    b->addElement(30, status);
    b->addElement(15, status);
    a->retainAll(*b);
    TEST_ASSERT(a->size() == 3);
    b->removeElementAt(1);
    a->retainAll(*b);
    TEST_ASSERT(a->contains(20) == FALSE);
    TEST_ASSERT(a->size() == 2);
    b->removeAllElements();
    TEST_ASSERT(b->size() == 0);
    a->retainAll(*b);
    TEST_ASSERT(a->size() == 0);
    TEST_CHECK_STATUS(status);
    delete a;
    delete b;

    //
    //  removeElementAt   Tested above.
    //

    //
    //  removeAllElments   Tested above
    //

    //
    //  size()   tested above
    //

    //
    //  isEmpty
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    TEST_ASSERT(a->isEmpty() == TRUE);
    a->addElement(10, status);
    TEST_ASSERT(a->isEmpty() == FALSE);
    a->addElement(20, status);
    a->removeElementAt(0);
    TEST_ASSERT(a->isEmpty() == FALSE);
    a->removeElementAt(0);
    TEST_ASSERT(a->isEmpty() == TRUE);
    TEST_CHECK_STATUS(status);
    delete a;


    //
    // ensureCapacity, expandCapacity
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    TEST_ASSERT(a->isEmpty() == TRUE);
    a->addElement(10, status);
    TEST_ASSERT(a->ensureCapacity(5000, status)== TRUE);
    TEST_ASSERT(a->expandCapacity(20000, status) == TRUE);
    TEST_CHECK_STATUS(status);
    delete a;
    
    //
    // setSize
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    a->setSize(100);
    TEST_ASSERT(a->size() == 100);
    TEST_ASSERT(a->elementAti(0) == 10);
    TEST_ASSERT(a->elementAti(1) == 20);
    TEST_ASSERT(a->elementAti(2) == 30);
    TEST_ASSERT(a->elementAti(3) == 0);
    a->setElementAt(666, 99);
    a->setElementAt(777, 100);
    TEST_ASSERT(a->elementAti(99) == 666);
    TEST_ASSERT(a->elementAti(100) == 0);
    a->setSize(2);
    TEST_ASSERT(a->elementAti(1) == 20);
    TEST_ASSERT(a->elementAti(2) == 0);
    TEST_ASSERT(a->size() == 2);
    a->setSize(0);
    TEST_ASSERT(a->empty() == TRUE);
    TEST_ASSERT(a->size() == 0);

    TEST_CHECK_STATUS(status);
    delete a;

    //
    // containsNone
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    b = new UVector32(status);
    TEST_ASSERT(a->containsNone(*b) == TRUE);
    b->addElement(5, status);
    TEST_ASSERT(a->containsNone(*b) == TRUE);
    b->addElement(30, status);
    TEST_ASSERT(a->containsNone(*b) == FALSE);

    TEST_CHECK_STATUS(status);
    delete a;
    delete b;

    //
    // sortedInsert
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->sortedInsert(30, status);
    a->sortedInsert(20, status);
    a->sortedInsert(10, status);
    TEST_ASSERT(a->elementAti(0) == 10);
    TEST_ASSERT(a->elementAti(1) == 20);
    TEST_ASSERT(a->elementAti(2) == 30);

    TEST_CHECK_STATUS(status);
    delete a;

    //
    // getBuffer
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    int32_t *buf = a->getBuffer();
    TEST_ASSERT(buf[0] == 10);
    TEST_ASSERT(buf[1] == 20);
    a->setSize(20000);
    int32_t *resizedBuf;
    resizedBuf = a->getBuffer();
    //TEST_ASSERT(buf != resizedBuf); // The buffer might have been realloc'd
    TEST_ASSERT(resizedBuf[0] == 10);
    TEST_ASSERT(resizedBuf[1] == 20);

    TEST_CHECK_STATUS(status);
    delete a;


    //
    //  empty
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    TEST_ASSERT(a->empty() == TRUE);
    a->addElement(10, status);
    TEST_ASSERT(a->empty() == FALSE);
    a->addElement(20, status);
    a->removeElementAt(0);
    TEST_ASSERT(a->empty() == FALSE);
    a->removeElementAt(0);
    TEST_ASSERT(a->empty() == TRUE);
    TEST_CHECK_STATUS(status);
    delete a;


    //
    //  peeki
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    TEST_ASSERT(a->peeki() == 10);
    a->addElement(20, status);
    TEST_ASSERT(a->peeki() == 20);
    a->addElement(30, status);
    TEST_ASSERT(a->peeki() == 30);
    TEST_CHECK_STATUS(status);
    delete a;


    //
    // popi
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->addElement(10, status);
    a->addElement(20, status);
    a->addElement(30, status);
    TEST_ASSERT(a->popi() == 30);
    TEST_ASSERT(a->popi() == 20);
    TEST_ASSERT(a->popi() == 10);
    TEST_ASSERT(a->popi() == 0);
    TEST_ASSERT(a->isEmpty());
    TEST_CHECK_STATUS(status);
    delete a;

    //
    // push
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    TEST_ASSERT(a->push(10, status) == 10);
    TEST_ASSERT(a->push(20, status) == 20);
    TEST_ASSERT(a->push(30, status) == 30);
    TEST_ASSERT(a->size() == 3);
    TEST_ASSERT(a->popi() == 30);
    TEST_ASSERT(a->popi() == 20);
    TEST_ASSERT(a->popi() == 10);
    TEST_ASSERT(a->isEmpty());
    TEST_CHECK_STATUS(status);
    delete a;


    //
    // reserveBlock
    //
    status = U_ZERO_ERROR;
    a = new UVector32(status);
    a->ensureCapacity(1000, status);

    // TODO:

    TEST_CHECK_STATUS(status);
    delete a;

}
Esempio n. 28
0
static void didStartProvisionalLoadForFrame(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
{
    WKRetainPtr<WKStringRef> wkMIME(AdoptWK, WKFrameCopyMIMEType(frame));
    TEST_ASSERT(WKStringIsEmpty(wkMIME.get()));
}
bool test_osc_StateList()
{
  size_t i;
  osc::StateList slist(4096);

  // KEEP IN MIND that each state take its own size PLUS 64 BYTES.

  TEST_ASSERT_EQUAL(slist.numberOfStates(),0);
  TEST_ASSERT_EQUAL(slist.getQuota(),4096);

  osc::byte_t bytes1[] = {0,1,2,3,4};
  osc::Buffer buff1(bytes1,sizeof(bytes1));
  osc::State s1(buff1);

  // Test single add
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  slist.addState(&s1, 1, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);

  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test reset
  slist.reset();
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);

  // Test double add (same priority)
  slist.addState(&s1, 1, false);
  slist.addState(&s1, 1, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test multiple add (lower priority)
  slist.addState(&s1, 2, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test multiple add (higher priority)
  slist.addState(&s1, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test adding second state
  osc::byte_t bytes2[] = {0,2,2,3,4};
  osc::Buffer buff2(bytes2,sizeof(bytes2));
  osc::State s2(buff2);
  slist.addState(&s2, 1, false);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),
                    4096 - sizeof(bytes1) - sizeof(bytes2) - 128);

  // Test adding big state that removes other two
  osc::byte_t bigBytes1[4096 - 64];
  for (i = 0; i < sizeof(bigBytes1); i++)
  {
    bigBytes1[i] = (i & 0xff);
  }
  osc::Buffer bigBuff1(bigBytes1, sizeof(bigBytes1));
  osc::State bigState1(bigBuff1);
  slist.addState(&bigState1, 0, false);
  TEST_ASSERT_EQUAL(bigState1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);

  // Test adding state that bumps exactly one state out (based on time).
  slist.reset();
  osc::Buffer bigBuff2(bigBytes1, sizeof(bigBytes1) - 64 - sizeof(bytes1));
  osc::State bigState2(bigBuff2);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 0, false);
  slist.addState(&s1, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Lowest priority = freed first

  // Test adding state that bumps exactly one state out (based on priority).
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 1, false);
  slist.addState(&s1, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Same test, but with state reprioritization
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 0, false);
  slist.addState(&s1, 1, false);
  slist.addState(&s2, 2, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Make sure insertion at a lower priority doesn't downgrade
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 2, false);
  slist.addState(&s1, 1, false);
  slist.addState(&s2, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Now, bump out the big state by lowering the quota
  slist.setQuota(2048);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),0);
  slist.setQuota(4096);

  // Try removing a state manually
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 2, false);
  slist.addState(&s1, 1, false);
  slist.removeState(s2.getStateId());
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Insert a pre-acked state, check acked state retreival
  slist.addState(&s2, 1, true);
  slist.addState(&s1, 1, false);
  TEST_ASSERT(!(slist.isStateAcked(s1.getStateId())));
  TEST_ASSERT(slist.isStateAcked(s2.getStateId()));
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2);
  slist.ackState(s1.getStateId());
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s1);
  slist.addState(&s2, 1, false);
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2);

  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(0),0);
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(2),0);

  return true;
}
Esempio n. 30
0
double getLabuteAtomContribs(const ROMol &mol, std::vector<double> &Vi,
                             double &hContrib, bool includeHs, bool force) {
  TEST_ASSERT(Vi.size() == mol.getNumAtoms());
  if (!force && mol.hasProp(common_properties::_labuteAtomContribs)) {
    mol.getProp(common_properties::_labuteAtomContribs, Vi);
    mol.getProp(common_properties::_labuteAtomHContrib, hContrib);
    double res;
    mol.getProp(common_properties::_labuteASA, res);
    return res;
  }
  unsigned int nAtoms = mol.getNumAtoms();
  std::vector<double> rads(nAtoms);
  for (unsigned int i = 0; i < nAtoms; ++i) {
    rads[i] = PeriodicTable::getTable()->getRb0(
        mol.getAtomWithIdx(i)->getAtomicNum());
    Vi[i] = 0.0;
  }

  for (ROMol::ConstBondIterator bondIt = mol.beginBonds();
       bondIt != mol.endBonds(); ++bondIt) {
    const double bondScaleFacts[4] = {.1, 0, .2, .3};
    double Ri = rads[(*bondIt)->getBeginAtomIdx()];
    double Rj = rads[(*bondIt)->getEndAtomIdx()];
    double bij = Ri + Rj;
    if (!(*bondIt)->getIsAromatic()) {
      if ((*bondIt)->getBondType() < 4) {
        bij -= bondScaleFacts[(*bondIt)->getBondType()];
      }
    } else {
      bij -= bondScaleFacts[0];
    }
    double dij = std::min(std::max(fabs(Ri - Rj), bij), Ri + Rj);
    Vi[(*bondIt)->getBeginAtomIdx()] += Rj * Rj - (Ri - dij) * (Ri - dij) / dij;
    Vi[(*bondIt)->getEndAtomIdx()] += Ri * Ri - (Rj - dij) * (Rj - dij) / dij;
  }
  hContrib = 0.0;
  if (includeHs) {
    double Rj = PeriodicTable::getTable()->getRb0(1);
    for (unsigned int i = 0; i < nAtoms; ++i) {
      double Ri = rads[i];
      double bij = Ri + Rj;
      double dij = std::min(std::max(fabs(Ri - Rj), bij), Ri + Rj);
      Vi[i] += Rj * Rj - (Ri - dij) * (Ri - dij) / dij;
      hContrib += Ri * Ri - (Rj - dij) * (Rj - dij) / dij;
    }
  }

  double res = 0.0;
  for (unsigned int i = 0; i < nAtoms; ++i) {
    double Ri = rads[i];
    Vi[i] = M_PI * Ri * (4. * Ri - Vi[i]);
    res += Vi[i];
  }
  if (includeHs) {
    double Rj = PeriodicTable::getTable()->getRb0(1);
    hContrib = M_PI * Rj * (4. * Rj - hContrib);
    res += hContrib;
  }
  mol.setProp(common_properties::_labuteAtomContribs, Vi, true);
  mol.setProp(common_properties::_labuteAtomHContrib, hContrib, true);
  mol.setProp(common_properties::_labuteASA, res, true);

  return res;
}