void TestLoad(const char *testdata_path)
{
  ++gTotalTests;

  nsMetricsConfig config;
  ASSERT_TRUE(config.Init());

  nsCOMPtr<nsILocalFile> dataFile;
  NS_NewNativeLocalFile(nsDependentCString(testdata_path),
                        PR_TRUE, getter_AddRefs(dataFile));
  ASSERT_TRUE(dataFile);

  ASSERT_SUCCESS(dataFile->AppendNative(
                     NS_LITERAL_CSTRING("test_config.xml")));
  ASSERT_SUCCESS(config.Load(dataFile));

  ASSERT_TRUE(config.IsEventEnabled(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
                                    NS_LITERAL_STRING("foo")));
  ASSERT_TRUE(config.IsEventEnabled(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
                                    NS_LITERAL_STRING("bar")));
  ASSERT_FALSE(config.IsEventEnabled(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
                                     NS_LITERAL_STRING("baz")));

  ASSERT_TRUE(config.EventLimit() == 200);
  ASSERT_TRUE(config.UploadInterval() == 1000);
  ASSERT_TRUE(config.HasConfig());
  ++gPassedTests;
}
Beispiel #2
0
TEST(plankton, cycles) {
  CREATE_RUNTIME();

  value_t i0 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species));
  value_t k0 = new_integer(78);
  ASSERT_SUCCESS(set_instance_field(runtime, i0, k0, i0));
  value_t d0 = transcode_plankton(runtime, NULL, NULL, i0);
  ASSERT_SAME(d0, get_instance_field(d0, k0));

  value_t i1 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species));
  value_t i2 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species));
  value_t i3 = new_heap_instance(runtime, ROOT(runtime, empty_instance_species));
  value_t k1 = new_integer(79);
  ASSERT_SUCCESS(set_instance_field(runtime, i1, k0, i2));
  ASSERT_SUCCESS(set_instance_field(runtime, i1, k1, i3));
  ASSERT_SUCCESS(set_instance_field(runtime, i2, k1, i3));
  ASSERT_SUCCESS(set_instance_field(runtime, i3, k0, i1));
  value_t d1 = transcode_plankton(runtime, NULL, NULL, i1);
  value_t d2 = get_instance_field(d1, k0);
  value_t d3 = get_instance_field(d1, k1);
  ASSERT_NSAME(d1, d2);
  ASSERT_NSAME(d1, d3);
  ASSERT_SAME(d3, get_instance_field(d2, k1));
  ASSERT_SAME(d1, get_instance_field(d3, k0));


  DISPOSE_RUNTIME();
}
Beispiel #3
0
//TODO: add more tests
static bool testAreDuplicateIngredients() {

	Ingredient ing1 = ingredientInitialize("99 little bugs in the code", MEATY, 1, 1, 1, NULL);
	Ingredient ing2 = ingredientInitialize("99 little bugs in the code", MEATY, 1, 1, 1, NULL);
	Ingredient ing3 = ingredientInitialize("Fix one, Patch it up", MEATY, 1, 1, 1, NULL);
	Ingredient ing4 = ingredientInitialize("127 little bugs in the code", MEATY, 1, 1, 1, NULL);

	Dish dish1 = dishCreate("Buggy Code", "Myself", 5);
	Dish dish2 = dishCreate("Laggy Code", "You", 5);
	bool isDuplicate;

	dishAddIngredient(dish1, ing1);
	dishAddIngredient(dish1, ing2);
	ASSERT_SUCCESS(dishAreDuplicateIngredients(dish1, &isDuplicate));
	ASSERT_TRUE(isDuplicate);

	dishAddIngredient(dish2, ing3);
	dishAddIngredient(dish2, ing4);
	ASSERT_SUCCESS(dishAreDuplicateIngredients(dish2, &isDuplicate));
	ASSERT_FALSE(isDuplicate);

	dishDestroy(dish1);
	dishDestroy(dish2);
	return true;
}
Beispiel #4
0
// Encodes and decodes a plankton value and returns the result.
static value_t transcode_plankton(runtime_t *runtime, value_mapping_t *resolver,
    value_mapping_t *access, value_t value) {
  // Encode and decode the value.
  value_t encoded = plankton_serialize(runtime, resolver, value);
  ASSERT_SUCCESS(encoded);
  value_t decoded = plankton_deserialize(runtime, access, encoded);
  ASSERT_SUCCESS(decoded);
  return decoded;
}
Beispiel #5
0
static int check(const struct TEST_VECTOR *test)
{
    unsigned char out[MAX_OUT_LEN];
    struct BLOCK_MODE_STATE ctx;
    size_t total = 0, out_len;
    struct BLOCK_STATE blk;

    if (!prim_avail(test->cipher))
        return 1;

    ASSERT_SUCCESS(block_init(&blk, test->key, test->key_len, test->cipher, 0));

    ASSERT_SUCCESS(block_mode_init(&ctx, &blk, test->iv, test->iv_len, 1,
                                   BLOCK_MODE_ECB, test->use_params
                                                 ? &test->params
                                                 : 0));

    block_mode_update(&ctx, &blk, test->in, test->in_len,
                      out, &out_len);
    total += out_len;

    ASSERT_SUCCESS(block_mode_final(&ctx, &blk,  out + total, &out_len));

    total += out_len;

    ASSERT_EQ(total, test->out_len);

    ASSERT_BUF_EQ(out, test->out, test->out_len);

    total = 0;

    ASSERT_SUCCESS(block_mode_init(&ctx, &blk, test->iv, test->iv_len, 0,
                                   BLOCK_MODE_ECB, test->use_params
                                                 ? &test->params
                                                 : 0));

    block_mode_update(&ctx, &blk, test->out, test->out_len,
                      out, &out_len);
    total += out_len;

    ASSERT_SUCCESS(block_mode_final(&ctx, &blk, out + total, &out_len));

    total += out_len;

    ASSERT_EQ(total, test->in_len);

    ASSERT_BUF_EQ(out, test->in, test->in_len);

    block_final(&blk);

    return 1;
}
Beispiel #6
0
//TODO: add more tests
static bool testHowMuchTasty() {

	Dish dish = dishCreate("Tasty", "Me of course", 1);

	ASSERT_SUCCESS(dishTaste(dish, true));
	ASSERT_SUCCESS(dishTaste(dish, true));
	ASSERT_SUCCESS(dishTaste(dish, false));

	double tastiness;
	ASSERT_SUCCESS(dishHowMuchTasty(dish, &tastiness));
	ASSERT_DOUBLE_EQUALS(tastiness, (double)2 / 3);

	dishDestroy(dish);
	return true;
}
Beispiel #7
0
TEST(plankton, instance) {
  CREATE_RUNTIME();

  value_t instance = new_heap_instance(runtime, ROOT(runtime, empty_instance_species));
  check_plankton(runtime, instance);
  DEF_HEAP_STR(x, "x");
  ASSERT_SUCCESS(try_set_instance_field(instance, x, new_integer(8)));
  DEF_HEAP_STR(y, "y");
  ASSERT_SUCCESS(try_set_instance_field(instance, y, new_integer(13)));
  value_t decoded = check_plankton(runtime, instance);
  ASSERT_SUCCESS(decoded);
  ASSERT_VALEQ(new_integer(8), get_instance_field(decoded, x));

  DISPOSE_RUNTIME();
}
Beispiel #8
0
PHP_METHOD(Rows, nextPageAsync)
{
  cassandra_rows* self = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  cassandra_future_rows* future_rows = NULL;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (!(self->result && cass_result_has_more_pages(self->result))) {
    object_init_ex(return_value, cassandra_future_value_ce);
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state(self->statement->statement, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, self->statement->statement);

  object_init_ex(return_value, cassandra_future_rows_ce);
  future_rows = (cassandra_future_rows*) zend_object_store_get_object(return_value TSRMLS_CC);

  Z_ADDREF_P(self->session);
  future_rows->session   = self->session;
  future_rows->statement = php_cassandra_add_ref(self->statement);
  future_rows->future    = future;
}
Beispiel #9
0
TEST(syntax, emitting) {
  CREATE_RUNTIME();

  value_t ast = new_heap_literal_ast(runtime, yes());
  assembler_t assm;
  ASSERT_SUCCESS(assembler_init(&assm, runtime, nothing(), scope_get_bottom()));
  ASSERT_SUCCESS(emit_value(ast, &assm));
  assembler_emit_return(&assm);
  value_t code = assembler_flush(&assm);
  ASSERT_SUCCESS(code);
  value_t result = run_code_block_until_condition(ambience, code);
  ASSERT_VALEQ(yes(), result);
  assembler_dispose(&assm);

  DISPOSE_RUNTIME();
}
Beispiel #10
0
void bulk_nhgm_consumer_worker()
{
    std::string tableName = ASIC_STATE_TABLE;
    swss::DBConnector db(ASIC_DB, "localhost", 6379, 0);
    swss::ConsumerTable c(&db, tableName);
    swss::Select cs;
    swss::Selectable *selectcs;
    int tmpfd;
    int ret = 0;

    cs.addSelectable(&c);
    while ((ret = cs.select(&selectcs, &tmpfd)) == swss::Select::OBJECT)
    {
        swss::KeyOpFieldsValuesTuple kco;
        c.pop(kco);

        auto& key = kfvKey(kco);
        auto& op = kfvOp(kco);

        if (starts_with(key, "SAI_OBJECT_TYPE_SWITCH")) continue;

        if (op == "bulkcreate")
        {
            sai_status_t status = processBulkEvent((sai_common_api_t)SAI_COMMON_API_BULK_CREATE, kco);
            ASSERT_SUCCESS("Failed to processBulkEvent");
            break;
        }

    }
}
Beispiel #11
0
Semaphore::~Semaphore() {
	// TODO Auto-generated destructor stub
	int res = -1;

	res = sem_destroy(&m_Sem);
	ASSERT_SUCCESS(res);
}
Beispiel #12
0
//TODO: add more tests
static bool testAddIngredient() {

	Dish dish = dishCreate("Shanim Hasumot", "Shanim Bli Regesh", 2);
	Ingredient ing1 = ingredientInitialize("Shanim Mehatsad", MEATY, 1, 1, 1, NULL);
	Ingredient ing2 = ingredientInitialize("Menutak", MILKY, 1, 1, 1, NULL);
	Ingredient ing3 = ingredientInitialize("Male Be-Uvdot", PARVE, 1, 1, 1, NULL);

	ASSERT_NULL_ARGUMENT(dishAddIngredient(NULL, ing1));

	ASSERT_SUCCESS(dishAddIngredient(dish, ing1));
	ASSERT_KOSHER_VIOLATION(dishAddIngredient(dish, ing2));
	ASSERT_SUCCESS(dishAddIngredient(dish, ing1));
	ASSERT_FULL(dishAddIngredient(dish, ing3));

	dishDestroy(dish);
	return true;
}
void TestSave(const char *temp_data_path)
{
  ++gTotalTests;
  static const char kFilename[] = "test-save.xml";
  static const char kExpectedContents[] =
    "<response xmlns=\"http://www.mozilla.org/metrics\"><config>"
    "<collectors>"
      "<collector type=\"uielement\"/>"
    "</collectors>"
    "<limit events=\"300\"/>"
    "<upload interval=\"500\"/>"
    "</config></response>";

  nsMetricsConfig config;
  ASSERT_TRUE(config.Init());

  // The data file goes to the current directory
  config.SetEventEnabled(NS_LITERAL_STRING(NS_METRICS_NAMESPACE),
                         NS_LITERAL_STRING("uielement"), PR_TRUE);
  config.SetUploadInterval(500);
  config.SetEventLimit(300);

  nsCOMPtr<nsILocalFile> outFile;
  NS_NewNativeLocalFile(nsDependentCString(temp_data_path),
                        PR_TRUE, getter_AddRefs(outFile));
  ASSERT_TRUE(outFile);
  ASSERT_SUCCESS(outFile->AppendNative(nsDependentCString(kFilename)));

  ASSERT_SUCCESS(config.Save(outFile));
  ASSERT_TRUE(CheckFileContents(outFile, kExpectedContents));

  // Now test with no collectors
  static const char kExpectedOutputNoEvents[] =
    "<response xmlns=\"http://www.mozilla.org/metrics\"><config>"
    "<collectors/>"
    "<limit events=\"300\"/>"
    "<upload interval=\"500\"/>"
    "</config></response>";

  config.ClearEvents();
  ASSERT_SUCCESS(config.Save(outFile));
  ASSERT_TRUE(CheckFileContents(outFile, kExpectedOutputNoEvents));

  ++gPassedTests;
}
Beispiel #14
0
//TODO: add more tests
static bool testGetName() {

	Dish dish = dishCreate("Boiled Student", "Stav Doolman", 2);

	char* name;
	ASSERT_SUCCESS(dishGetName(dish, &name));
	ASSERT_STRING_EQUALS(name, "Boiled Student");
	name[0] = 'B';

	char* dupName;
	ASSERT_SUCCESS(dishGetName(dish, &dupName));
	ASSERT_STRING_EQUALS(dupName, "Boiled Student");

	free(name);
	free(dupName);
	dishDestroy(dish);
	return true;
}
Beispiel #15
0
//TODO: add more tests
static bool testSetName() {

	Dish dish = dishCreate("Sweet & Sour Dor", "Ofer Givoli", 2);

	ASSERT_SUCCESS(dishSetName(dish, "Just Dor"));
	char* name;
	dishGetName(dish, &name);
	ASSERT_STRING_EQUALS(name, "Just Dor");
	free(name);

	char newName[] = "New Blabla";
	ASSERT_SUCCESS(dishSetName(dish, newName));
	newName[0] = 'M';
	dishGetName(dish, &name);
	ASSERT_STRING_EQUALS(name, "New Blabla");
	free(name);

	dishDestroy(dish);
	return true;
}
Beispiel #16
0
//TODO: add more tests
static bool testRemoveIngredient() {

	ASSERT_NULL_ARGUMENT(dishRemoveIngredient(NULL, -1));

	Dish dish = dishCreate("Hasrot Kol Ereh", "Ha Keisar Shel Yapan", 2);
	Ingredient ing1 = ingredientInitialize("Ha Keisar Shel Yapan", MEATY, 1, 1, 1, NULL);

	ASSERT_INGREDIENT_NOT_FOUND(dishRemoveIngredient(dish, 4));
	ASSERT_INGREDIENT_NOT_FOUND(dishRemoveIngredient(dish, -2));

	dishAddIngredient(dish, ing1);
	dishAddIngredient(dish, ing1);

	ASSERT_SUCCESS(dishRemoveIngredient(dish, 0));
	ASSERT_SUCCESS(dishRemoveIngredient(dish, 0));
	ASSERT_INGREDIENT_NOT_FOUND(dishRemoveIngredient(dish, 0));

	dishDestroy(dish);
	return true;
}
Beispiel #17
0
//TODO: add more tests
static bool testGetCook() {

	Dish dish = dishCreate("Rotten Shlomo", "Sarai Duek", 2);

	char* cook;
	ASSERT_SUCCESS(dishGetCook(dish, &cook));
	ASSERT_STRING_EQUALS(cook, "Sarai Duek");

	free(cook);
	dishDestroy(dish);
	return true;
}
Beispiel #18
0
PHP_METHOD(Rows, nextPage)
{
  zval* timeout = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  const CassResult* result = NULL;
  cassandra_rows* rows = NULL;

  cassandra_rows* self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (!(self->result && cass_result_has_more_pages(self->result)))
    return;

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state(self->statement->statement, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, self->statement->statement);

  if (php_cassandra_future_wait_timed(future, timeout TSRMLS_CC) == FAILURE) {
    return;
  }

  if (php_cassandra_future_is_error(future TSRMLS_CC) == FAILURE) {
    return;
  }

  result = cass_future_get_result(future);

  if (!result) {
    zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                            "Future doesn't contain a result.");
    return;
  }

  object_init_ex(return_value, cassandra_rows_ce);
  rows = (cassandra_rows*) zend_object_store_get_object(return_value TSRMLS_CC);

  if (php_cassandra_get_result(result, &rows->rows TSRMLS_CC) == FAILURE) {
    cass_result_free(result);
    zval_dtor(return_value);
    return;
  }

  Z_ADDREF_P(self->session);
  rows->statement = php_cassandra_add_ref(self->statement);
  rows->session   = self->session;
  rows->result    = result;
}
Beispiel #19
0
VOID
BenchmarkThreadPool(
    PLW_THREAD_POOL pPool,
    PBENCHMARK_SETTINGS pSettings,
    PULONG64 pullDuration,
    PULONG64 pullBytesTransferred
    )
{
    PLW_TASK_GROUP pGroup = NULL;
    PSOCKET* ppSockets1 = NULL;
    PSOCKET* ppSockets2 = NULL;
    size_t i = 0;
    ULONG64 ullTotal = 0;
    LONG64 llStart = 0;
    LONG64 llEnd = 0;
    ULONG64 ullTime = 0;
    NTSTATUS status;

    gpPool = pPool;
    gpSettings = pSettings;

    status = LwRtlCreateTaskGroup(gpPool, &pGroup);
    ASSERT_SUCCESS(status);

    status = LW_RTL_ALLOCATE_ARRAY_AUTO(&ppSockets1, gpSettings->ulPairs);
    ASSERT_SUCCESS(status);

    status = LW_RTL_ALLOCATE_ARRAY_AUTO(&ppSockets2, gpSettings->ulPairs);
    ASSERT_SUCCESS(status);

    for (i = 0; i < gpSettings->ulPairs; i++)
    {
        NTSTATUS status = CreateSocketPair(pGroup, &ppSockets1[i], &ppSockets2[i]);
        
        ASSERT_SUCCESS(status);
    }
    
    status = TimeNow(&llStart);
    ASSERT_SUCCESS(status);
    
    LwRtlWakeTaskGroup(pGroup);
    LwRtlWaitTaskGroup(pGroup);
    
    status = TimeNow(&llEnd);
    ASSERT_SUCCESS(status);
    
    ullTime = (ULONG64) (llEnd - llStart);
    
    LwRtlFreeTaskGroup(&pGroup);

    for (i = 0; i < gpSettings->ulPairs; i++)
    {
        ullTotal += ppSockets1[i]->ullTotalTransferred;
    }

    *pullDuration = ullTime;
    *pullBytesTransferred = ullTotal;
}
Beispiel #20
0
void test_enable_recording()
{
    SWSS_LOG_ENTER();

    sai_attribute_t attr;
    attr.id = SAI_REDIS_SWITCH_ATTR_RECORD;
    attr.value.booldata = true;

    sai_switch_api_t *sai_switch_api = NULL;

    sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);

    sai_status_t status = sai_switch_api->set_switch_attribute(SAI_NULL_OBJECT_ID, &attr);

    ASSERT_SUCCESS("Failed to enable recording");
}
Beispiel #21
0
void test_sai_initialize()
{
    SWSS_LOG_ENTER();

    // NOTE: this is just testing whether test application will
    // link against libsairedis, this api requires running redis db
    // with enabled unix socket
    sai_status_t status = sai_api_initialize(0, (service_method_table_t*)&test_services);

    // Mock the SAI api
    test_next_hop_group_api.create_next_hop_group_member = test_create_next_hop_group_member;
    sai_metadata_sai_next_hop_group_api = &test_next_hop_group_api;
    created_next_hop_group_member.clear();

    ASSERT_SUCCESS("Failed to initialize api");
}
Beispiel #22
0
//TODO: add more tests
static bool testGetQuality() {

	Dish dish = dishCreate("En Yoter Pahad", "En Yoter Klum", 2);
	Ingredient ing1 = ingredientInitialize("Ani Ish Kash", PARVE, 2000, 1, 1, NULL);
	Ingredient ing2 = ingredientInitialize("Ani Etz Akum", PARVE, 0, 10, 1, NULL);

	dishAddIngredient(dish, ing1);
	dishAddIngredient(dish, ing2);

	double quality;
	ASSERT_SUCCESS(dishGetQuality(dish, &quality));
	ASSERT_DOUBLE_EQUALS(quality, 5);

	dishDestroy(dish);
	return true;
}
Beispiel #23
0
static int check(const struct TEST_VECTOR *test)
{
    unsigned char out[MAX_OUT_LEN];

    if (!prim_avail(test->hash))
        return 1;

    ASSERT_SUCCESS(kdf_hkdf(test->hash, 0,
                            test->key, test->key_len,
                            test->salt, test->salt_len,
                            test->info, test->info_len,
                            out, test->out_len));

    ASSERT_BUF_EQ(out, test->out, test->out_len);

    return 1;
}
Beispiel #24
0
PHP_METHOD(Rows, nextPageAsync)
{
  cassandra_rows* self = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  cassandra_future_rows* future_rows = NULL;
  cassandra_future_value* future_value;

  if (zend_parse_parameters_none() == FAILURE)
    return;

  self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->future_next_page) {
    RETURN_ZVAL(self->future_next_page, 1, 0);
  }

  if (self->next_page) {
    Z_ADDREF_P(self->next_page);
    object_init_ex(self->future_next_page, cassandra_future_value_ce);
    future_value = (cassandra_future_value*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);
    future_value->value = self->next_page;
    RETURN_ZVAL(self->future_next_page, 1, 0);
  }

  if (self->result == NULL) {
    object_init_ex(return_value, cassandra_future_value_ce);
    return;
  }

  ASSERT_SUCCESS(cass_statement_set_paging_state((CassStatement*) self->statement->data, self->result));

  session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
  future = cass_session_execute(session->session, (CassStatement*) self->statement->data);

  object_init_ex(self->future_next_page, cassandra_future_rows_ce);
  future_rows = (cassandra_future_rows*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);

  Z_ADDREF_P(self->session);
  future_rows->session   = self->session;
  future_rows->statement = php_cassandra_add_ref(self->statement);
  future_rows->future    = future;

  php_cassandra_rows_clear(self);
  RETURN_ZVAL(self->future_next_page, 1, 0);
}
Beispiel #25
0
//TODO: add more tests
static bool testIsBetter() {

	Dish dish1 = dishCreate("Reva Shaa", "Mehake Barehov", 2);
	Dish dish2 = dishCreate("Lahaver Harusi", "Hadash", 2);

	Ingredient ing1 = ingredientInitialize("Dor", MEATY, 0, 4, 20, NULL);
	Ingredient ing2 = ingredientInitialize("Cohen", MEATY, 0, 6, 30, NULL);

	dishAddIngredient(dish1, ing1);
	dishAddIngredient(dish2, ing2);

	bool isBetter;
	ASSERT_SUCCESS(dishIsBetter(dish2, dish1, 0.7, &isBetter));
	ASSERT_TRUE(isBetter);

	dishDestroy(dish1);
	dishDestroy(dish2);
	return true;
}
Beispiel #26
0
static int check(const struct TEST_VECTOR *test)
{
    unsigned char out[MAX_OUT_LEN];
    struct BLOCK_STATE state;

    ASSERT_SUCCESS(block_init(&state, test->key, test->key_len,
                              BLOCK_AES, test->use_params
                                       ? &test->params
                                       : 0));

    memcpy(out, test->in, test->in_len);

    block_forward(&state, out);

    ASSERT_BUF_EQ(out, test->out, test->out_len);

    block_inverse(&state, out);

    ASSERT_BUF_EQ(out, test->in, test->in_len);

    block_final(&state);

    return 1;
}
Beispiel #27
0
void Semaphore::Wait() {
	int res = sem_wait(&m_Sem);
	ASSERT_SUCCESS(res);
}
Beispiel #28
0
void Semaphore::Post() {
	int res = sem_post(&m_Sem);
	ASSERT_SUCCESS(res);
}
Beispiel #29
0
Semaphore::Semaphore() {
	// TODO Auto-generated constructor stub
	int res = sem_init(&m_Sem, 0, 0);
	ASSERT_SUCCESS(res);
}
Beispiel #30
0
PHP_METHOD(Rows, nextPage)
{
  zval* timeout = NULL;
  cassandra_session* session = NULL;
  CassFuture* future = NULL;
  const CassResult* result = NULL;
  cassandra_rows* rows = NULL;
  cassandra_future_rows* future_rows = NULL;

  cassandra_rows* self = (cassandra_rows*) zend_object_store_get_object(getThis() TSRMLS_CC);

  if (self->next_page) {
    RETURN_ZVAL(self->next_page, 1, 0);
  }

  if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|z", &timeout) == FAILURE) {
    return;
  }

  if (self->future_next_page) {
    if (!instanceof_function(Z_OBJCE_P(self->future_next_page),
                             cassandra_future_rows_ce TSRMLS_CC)) {
      zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                              "Unexpected future instance.");
      return;
    }

    future_rows = (cassandra_future_rows*) zend_object_store_get_object(self->future_next_page TSRMLS_CC);

    if (php_cassandra_future_wait_timed(future_rows->future, timeout TSRMLS_CC) == FAILURE) {
      return;
    }

    if (php_cassandra_future_is_error(future_rows->future TSRMLS_CC) == FAILURE) {
      return;
    }

    result = cass_future_get_result(future_rows->future);
  } else {
    if (self->result == NULL) {
      return;
    }

    ASSERT_SUCCESS(cass_statement_set_paging_state((CassStatement*) self->statement->data, self->result));

    session = (cassandra_session*) zend_object_store_get_object(self->session TSRMLS_CC);
    future = cass_session_execute(session->session, (CassStatement*) self->statement->data);

    if (php_cassandra_future_wait_timed(future, timeout TSRMLS_CC) == FAILURE) {
      return;
    }

    if (php_cassandra_future_is_error(future TSRMLS_CC) == FAILURE) {
      return;
    }

    result = cass_future_get_result(future);
    cass_future_free(future);
  }

  if (!result) {
    zend_throw_exception_ex(cassandra_runtime_exception_ce, 0 TSRMLS_CC,
                            "Future doesn't contain a result.");
    return;
  }

  MAKE_STD_ZVAL(self->next_page);
  object_init_ex(self->next_page, cassandra_rows_ce);
  rows = (cassandra_rows*) zend_object_store_get_object(self->next_page TSRMLS_CC);

  if (php_cassandra_get_result(result, &rows->rows TSRMLS_CC) == FAILURE) {
    cass_result_free(result);
    zval_dtor(self->next_page);
    self->next_page = NULL;
    return;
  }

  if (self->future_next_page) {
    zval_ptr_dtor(&self->future_next_page);
    self->future_next_page = NULL;
  }

  if (cass_result_has_more_pages(result)) {
    Z_ADDREF_P(self->session);
    rows->statement = php_cassandra_add_ref(self->statement);
    rows->session   = self->session;
    rows->result    = result;
  } else {
    cass_result_free(result);
  }

  php_cassandra_rows_clear(self);
  RETURN_ZVAL(self->next_page, 1, 0);
}