Ejemplo n.º 1
0
static void
test_dom_tree_to_commodity_ref(void)
{
    int i;
    for (i = 0; i < 20; i++)
    {
        gnc_commodity *test_com1;
        gchar *test_str1;
        gchar *test_str2;
        gnc_commodity *test_com2;
        xmlNodePtr test_node;
        QofBook *book;

        book = qof_book_new ();

        test_str1 = get_random_string();
        test_str2 = get_random_string();

        test_com1 = gnc_commodity_new(book, NULL, test_str1, test_str2, NULL, 0);
        test_node = commodity_ref_to_dom_tree("test-com", test_com1);

        test_com2 = dom_tree_to_commodity_ref_no_engine(test_node, book);

        do_test(gnc_commodity_equiv(test_com1, test_com2),
                "dom_tree_to_commodity_ref_no_engine");

        xmlFreeNode(test_node);
        gnc_commodity_destroy(test_com1);
        gnc_commodity_destroy(test_com2);
        g_free(test_str1);
        g_free(test_str2);

        qof_book_destroy (book);
    }
}
    /// Test the blob name with corner characters.
    TEST_FIXTURE(blob_test_base, corner_blob_name)
    {
        // Initialize the chareset to generate random blob name.
        std::vector<utility::char_t> charset;
        utility::string_t characters = _XPLATSTR("`~!@#$%^&*()_+[{]}|;:\'\",<>?");
        for (size_t i = 0; i < characters.size(); ++i)
        {
            charset.push_back(characters[i]);
        }

        for (int i = 0; i < 16; ++i)
        {
            utility::string_t blob_name = get_random_string(charset, 20);
            azure::storage::cloud_block_blob blob = m_container.get_block_blob_reference(blob_name);
            auto content = get_random_string(charset, 20);
            blob.upload_text(content);

            // list the container to get the blob just created.
            auto listing = list_all_blobs(blob_name, azure::storage::blob_listing_details::all, 0, azure::storage::blob_request_options());
            CHECK(listing.size() == 1);

            // check the consistance of blob content.
            auto download_content = blob.download_text();
            CHECK(content == download_content);

            blob.delete_blob();
        }
    }
Ejemplo n.º 3
0
utility::string_t get_object_name(const utility::string_t& object_type_name)
{
    utility::string_t object_name;
    object_name.reserve(37U + object_type_name.size());
    object_name.append(object_name_prefix);
    object_name.append(object_type_name);
    object_name.append(get_random_string());
    return object_name;
}
Ejemplo n.º 4
0
static void test_create_ust_event_exclusion(void)
{
	struct ltt_ust_event *event;
	struct lttng_event ev;
	char *name;
	struct lttng_event_exclusion *exclusion;

	memset(&ev, 0, sizeof(ev));

	/* make a wildcarded event name */
	name = get_random_string();
	name[strlen(name) - 1] = '*';
	strncpy(ev.name, name, LTTNG_SYMBOL_NAME_LEN);

	ev.type = LTTNG_EVENT_TRACEPOINT;
	ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;

	/* set up an exclusion set */
	exclusion = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN);
	if (!exclusion) {
		PERROR("zmalloc");
	}

	ok(exclusion != NULL, "Create UST exclusion");

	exclusion->count = 1;
	strncpy((char *)(exclusion->names), get_random_string(), LTTNG_SYMBOL_NAME_LEN);

	event = trace_ust_create_event(&ev, NULL, NULL, exclusion);

	ok(event != NULL, "Create UST event with exclusion");

	ok(event->enabled == 0 &&
	   event->attr.instrumentation == LTTNG_UST_TRACEPOINT &&
	   strcmp(event->attr.name, ev.name) == 0 &&
	   event->exclusion != NULL &&
	   event->exclusion->count == 1 &&
	   strcmp((char *)(event->exclusion->names), (char *)(exclusion->names)) == 0 &&
	   event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0',
	   "Validate UST event and exclusion");

	trace_ust_destroy_event(event);
}
Ejemplo n.º 5
0
static void
test_string_fcn (GncAddress *address, const char *message,
                 void (*set) (GncAddress *, const char *str),
                 const char * (*get)(const GncAddress *))
{
    char const *str = get_random_string ();

    do_test (!gncAddressIsDirty (address), "test if start dirty");
    set (address, str);
    do_test (gncAddressIsDirty (address), "test dirty later");
    do_test (g_strcmp0 (get (address), str) == 0, message);
    gncAddressClearDirty (address);
}
Ejemplo n.º 6
0
pairs_st *pairs_generate(uint64_t number_of, size_t value_length)
{
  unsigned int x;
  pairs_st *pairs;

  pairs= (pairs_st*)calloc((size_t)number_of + 1, sizeof(pairs_st));

  if (!pairs)
    goto error;

  for (x= 0; x < number_of; x++)
  {
    pairs[x].key= (char *)calloc(100, sizeof(char));
    if (!pairs[x].key)
      goto error;
    get_random_string(pairs[x].key, 100);
    pairs[x].key_length= 100;

    if (value_length)
    {
      pairs[x].value= (char *)calloc(value_length, sizeof(char));
      if (!pairs[x].value)
        goto error;
      get_random_string(pairs[x].value, value_length);
      pairs[x].value_length= value_length;
    }
    else
    {
      pairs[x].value= NULL;
      pairs[x].value_length= 0;
    }
  }

  return pairs;
error:
    fprintf(stderr, "Memory Allocation failure in pairs_generate.\n");
    exit(0);
}
Ejemplo n.º 7
0
// create max_files and fill with random data
// return list of {file name, content md5}
static GList *populate_file_list (gint max_files, GList *l_files, gchar *in_dir)
{
    gint i;
    gchar *out_dir;
    GError *error = NULL;
    FileData *fdata;
    gchar *name;
    FILE *f;

    out_dir = g_dir_make_tmp (NULL, &error);
    g_assert (out_dir);


    LOG_debug (POOL_TEST, "In dir: %s   Out dir: %s", in_dir, out_dir);

    for (i = 0; i < max_files; i++) {
        char *bytes;
        size_t bytes_len;

        fdata = g_new0 (FileData, 1);
        fdata->checked = FALSE;
        bytes_len = g_random_int_range (100000, 1000000);
        bytes = g_malloc (bytes_len + 1);
        RAND_pseudo_bytes ((unsigned char *)bytes, bytes_len);
        *(bytes + bytes_len) = '\0';
        
        name = get_random_string (15, TRUE);
        fdata->in_name = g_strdup_printf ("%s/%s", in_dir, name);
        f = fopen (fdata->in_name, "w");
        fwrite (bytes, 1, bytes_len + 1, f);
        fclose (f);

        fdata->out_name = g_strdup_printf ("%s/%s", out_dir, name);
        get_md5_sum (bytes, bytes_len + 1, &fdata->md5, NULL);
        
        fdata->fout = fopen (fdata->out_name, "w");
        g_assert (fdata->fout);

        fdata->url = g_strdup_printf ("http://127.0.0.1:8011/%s", name);
        g_assert (fdata->url);
        
        LOG_debug (POOL_TEST, "%s -> %s, size: %u", fdata->in_name, fdata->md5, bytes_len);
        
        l_files = g_list_append (l_files, fdata);
    }

    return l_files;
}
Ejemplo n.º 8
0
static void
test_string_fcn (QofBook *book, const char *message,
                 void (*set) (GncEmployee *, const char *str),
                 const char * (*get)(const GncEmployee *))
{
    GncEmployee *employee = gncEmployeeCreate (book);
    char const *str = get_random_string ();

    do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
    gncEmployeeBeginEdit (employee);
    set (employee, str);
    do_test (gncEmployeeIsDirty (employee), "test dirty later");
    gncEmployeeCommitEdit (employee);
    do_test (gncEmployeeIsDirty (employee), "test dirty after commit");
    do_test (safe_strcmp (get (employee), str) == 0, message);
    gncEmployeeSetActive (employee, FALSE);
    count++;
}
Ejemplo n.º 9
0
mychild*
child_create(QofBook *book)
{
    mychild *g;

    g_return_val_if_fail(book, NULL);
    g = g_object_new(GNC_TYPE_MYCHILD, NULL);
    qof_instance_init_data (&g->inst, CHILD_MODULE_NAME, book);
    g->date = *get_random_timespec();
    g->discount = get_random_double();
    g->active = get_random_boolean();
    g->version = get_random_int_in_range(1, 10000);
    g->minor = get_random_int_in_range(100001, 99999999);
    g->flag = get_random_character();
    g->Name = get_random_string();
    g->Amount = get_random_gnc_numeric();
    qof_event_gen(&g->inst, QOF_EVENT_CREATE, NULL);
    return g;
}
Ejemplo n.º 10
0
static void
test_dom_tree_to_text(void)
{
    int i;

    for (i = 0; i < 20; i++)
    {
        gchar *test_string1;
        gchar *test_string2;
        xmlNodePtr test_node;

        test_node = xmlNewNode(NULL, BAD_CAST "test-node");
        test_string1 = get_random_string();

        xmlNodeAddContent(test_node, BAD_CAST test_string1);

        test_string2 = dom_tree_to_text(test_node);

        if (!test_string2)
        {
            failure_args("dom_tree_to_text", __FILE__, __LINE__,
                         "null return from dom_tree_to_text");
            xmlElemDump(stdout, NULL, test_node);
        }
        else if (g_strcmp0(test_string1, test_string2) == 0)
        {
            success_args("dom_tree_to_text", __FILE__, __LINE__, "with string %s",
                         test_string1);
        }
        else
        {
            failure_args("dom_tree_to_text", __FILE__, __LINE__,
                         "with string %s", test_string1);
        }

        xmlFreeNode(test_node);
        g_free(test_string1);
        if (test_string2) g_free(test_string2);
    }
}
Ejemplo n.º 11
0
static void test_create_ust_event(void)
{
	struct ltt_ust_event *event;
	struct lttng_event ev;

	memset(&ev, 0, sizeof(ev));
	strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN);
	ev.type = LTTNG_EVENT_TRACEPOINT;
	ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;

	event = trace_ust_create_event(&ev, NULL, NULL, NULL);

	ok(event != NULL, "Create UST event");

	ok(event->enabled == 0 &&
	   event->attr.instrumentation == LTTNG_UST_TRACEPOINT &&
	   strcmp(event->attr.name, ev.name) == 0 &&
	   event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0',
	   "Validate UST event");

	trace_ust_destroy_event(event);
}
Ejemplo n.º 12
0
static void test_create_kernel_event(void)
{
	struct ltt_kernel_event *event;
	struct lttng_event ev;

	memset(&ev, 0, sizeof(ev));
	strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN);
	ev.type = LTTNG_EVENT_TRACEPOINT;
	ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;

	event = trace_kernel_create_event(&ev);
	ok(event != NULL, "Create kernel event");

	ok(event->fd == -1 &&
	   event->enabled == 1 &&
	   event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT &&
	   strlen(event->event->name),
	   "Validate kernel event");

	/* Init list in order to avoid sefaults from cds_list_del */
	CDS_INIT_LIST_HEAD(&event->list);
	trace_kernel_destroy_event(event);
}
Ejemplo n.º 13
0
static void
test_string_fcn (QofBook *book, const char *message,
                 void (*set) (GncEmployee *, const char *str),
                 const char * (*get)(const GncEmployee *))
{
    GncEmployee *employee = gncEmployeeCreate (book);
    char const *str = get_random_string ();

    do_test (!gncEmployeeIsDirty (employee), "test if start dirty");
    gncEmployeeBeginEdit (employee);
    set (employee, str);
    /* Employee record should be dirty */
    do_test (gncEmployeeIsDirty (employee), "test dirty later");
    gncEmployeeCommitEdit (employee);
    /* Employee record should be not dirty */
    /* Skip, because will always fail without a backend.
     * It's not possible to load a backend in the engine code
     * without having circular dependencies.
     */
    // do_test (!gncEmployeeIsDirty (employee), "test dirty after commit");
    do_test (g_strcmp0 (get (employee), str) == 0, message);
    gncEmployeeSetActive (employee, FALSE);
    count++;
}
Ejemplo n.º 14
0
static void
test_vendor (void)
{
    QofBook *book;
    GncVendor *vendor;

    book = qof_book_new();

    /* Test creation/destruction */
    {
        do_test (gncVendorCreate (NULL) == NULL, "vendor create NULL");
        vendor = gncVendorCreate (book);
        do_test (vendor != NULL, "vendor create");
        do_test (qof_instance_get_book (QOF_INSTANCE(vendor)) == book,
                 "getbook");

        gncVendorBeginEdit (vendor);
        gncVendorDestroy (vendor);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncVendorSetID, gncVendorGetID);
        test_string_fcn (book, "Name", gncVendorSetName, gncVendorGetName);
        test_string_fcn (book, "Notes", gncVendorSetNotes, gncVendorGetNotes);

        //test_string_fcn (book, "Terms", gncVendorSetTerms, gncVendorGetTerms);

        //test_bool_fcn (book, "TaxIncluded", gncVendorSetTaxIncluded, gncVendorGetTaxIncluded);
        test_bool_fcn (book, "Active", gncVendorSetActive, gncVendorGetActive);

        do_test (gncVendorGetAddr (vendor) != NULL, "Addr");

        guid_new (&guid);
        vendor = gncVendorCreate (book);
        count++;
        gncVendorSetGUID (vendor, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(vendor))), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_ID_VENDOR, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_ID_VENDOR, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;

        gncVendorSetName (vendor, str);
        res = qof_object_printable (GNC_ID_VENDOR, vendor);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    qof_book_destroy (book);
}
Ejemplo n.º 15
0
static void
test_customer (void)
{
    QofBook *book;
    GncCustomer *customer;

    book = qof_book_new ();

    /* Test creation/destruction */
    {
        do_test (gncCustomerCreate (NULL) == NULL, "customer create NULL");
        customer = gncCustomerCreate (book);
        do_test (customer != NULL, "customer create");
        do_test (gncCustomerGetBook (customer) == book, "getbook");

        gncCustomerBeginEdit (customer);
        gncCustomerDestroy (customer);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncCustomerSetID, gncCustomerGetID);
        test_string_fcn (book, "Name", gncCustomerSetName, gncCustomerGetName);
        test_string_fcn (book, "Notes", gncCustomerSetNotes, gncCustomerGetNotes);

        //test_string_fcn (book, "Terms", gncCustomerSetTerms, gncCustomerGetTerms);

        test_numeric_fcn (book, "Discount", gncCustomerSetDiscount, gncCustomerGetDiscount);
        test_numeric_fcn (book, "Credit", gncCustomerSetCredit, gncCustomerGetCredit);

        test_bool_fcn (book, "Active", gncCustomerSetActive, gncCustomerGetActive);

        do_test (gncCustomerGetAddr (customer) != NULL, "Addr");
        do_test (gncCustomerGetShipAddr (customer) != NULL, "ShipAddr");

        guid_replace (&guid);
        customer = gncCustomerCreate (book);
        count++;
        gncCustomerSetGUID (customer, &guid);
        do_test (guid_equal (&guid, gncCustomerGetGUID (customer)), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_ID_CUSTOMER, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_ID_CUSTOMER, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;

        res = NULL;
        gncCustomerBeginEdit(customer);
        gncCustomerSetName (customer, str);
        gncCustomerCommitEdit(customer);
        res = qof_object_printable (GNC_ID_CUSTOMER, customer);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    do_test (gncCustomerGetJoblist (customer, TRUE) == NULL, "joblist empty");

    /* Test the Entity Table */
    {
        const GncGUID *guid;

        guid = gncCustomerGetGUID (customer);
        do_test (gncCustomerLookup (book, guid) == customer, "Entity Table");
    }

    /* Note: JobList is tested from the Job tests */
    qof_book_destroy (book);
}
Ejemplo n.º 16
0
    std::string http_client::build_post(std::string& content_type, const string_to_stringmap& postvars, const string_to_stringmap& filenames_in) const
    {
        if ( postvars.empty() && filenames_in.empty() )
            return std::string();

        string_to_stringmap filenames = filenames_in;

        // sanitize the files
        if ( !filenames.empty() )
        {
            string_to_stringmap::iterator var_names = filenames.begin();
            while (var_names != filenames.end())
            {
                stringmap::iterator fnames = var_names->second.begin();

                while( fnames != var_names->second.end() )
                {
                    FILE *fp = ::fopen(fnames->second.c_str(), "rb");
                    if ( fp == NULL )
                    {
                        stringmap::iterator old_one = fnames++;
                        var_names->second.erase(old_one);
                    }
                    else
                    {
                        fclose(fp);
                        ++fnames;
                    }
                }

                if ( fnames->second.empty() )
                {
                    string_to_stringmap::iterator old_one = var_names++;
                    filenames.erase(old_one);
                }
                else
                {
                    ++var_names;
                }
            }
        }

        content_type = !filenames.empty() ? "multipart/form-data" : "application/x-www-form-urlencoded";
        std::stringstream postBody;
        if ( !filenames.empty() )
        {
            std::string mime_boundary = get_random_string(32);

            // First add the form vars
            for (string_to_stringmap::const_iterator ci = postvars.begin(); ci != postvars.end(); ++ci)
            {
                for (stringmap::const_iterator si = ci->second.begin(); si != ci->second.end(); ++si)
                {
                    postBody << "--" << mime_boundary << "\r\n"
                        "Content-Disposition: form-data; name=\"" << ci->first << "\"\r\n\r\n"
                        << si->second << "\r\n";
                }
            }

            // Then add the files
            for (string_to_stringmap::const_iterator ci = filenames.begin(); ci != filenames.end(); ++ci)
            {
                for (stringmap::const_iterator si = ci->second.begin(); si != ci->second.end(); ++si)
                {
                    std::ifstream in(si->second.c_str());
                    postBody << "--" << mime_boundary << "\r\n"
                        "Content-Disposition: form-data; name=\"" << ci->first << "\"; filename=\"" << get_basename(si->second) << "\"\r\n\r\n"
                        << in.rdbuf() << "\r\n";
                }
            }

            postBody << "--" << mime_boundary << "--\r\n";
        }
        else
        {
            // No files...
            for (string_to_stringmap::const_iterator ci = postvars.begin(); ci != postvars.end(); ++ci)
            {
                for (stringmap::const_iterator si = ci->second.begin(); si != ci->second.end(); ++si)
                {
                    postBody << urlencode(ci->first) << '=' << urlencode(si->second) << '&';
                }
            }

            // read the last '&'
            char c;
            postBody.read(&c, 1);
        }

        return postBody.str();
    }
Ejemplo n.º 17
0
static void
test_employee (void)
{
    QofBook *book;
    GncEmployee *employee;

    book = qof_book_new();

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_replace (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (g_strcmp0 (str, res) == 0, "Printable equals");
    }

    qof_book_destroy (book);
}
Ejemplo n.º 18
0
void CDBConnection::execute(const TBiddingTxnInput* pIn, TBiddingTxnOutput* pOut){
	pOut->status = CBaseTxnErr::SUCCESS;

	char query[4096];
	sql_result_t result;
	int length;
	char* val;
	int r = 0;

	string user_name;
	string item_description;
	string rec_description = get_random_string(128);
	uint64_t bid;
	uint64_t pid;
	double cur_price;
	double bid_price;

#ifndef QURO
	sprintf(query, SELECT_ITEM, pIn->item_id);
	//CLANG_PROFILE;
	r = dbt5_sql_execute(query, &result, "GET_ITEM");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		cur_price = atof(dbt5_sql_getvalue(&result, 0, length));
		val = dbt5_sql_getvalue(&result, 1, length);
		item_description.assign(val);
		dbt5_sql_close_cursor(&result);
	}else{
		FAIL_MSG("GET_ITEM FAIL");
	}

	sprintf(query, GET_USER, pIn->user_id);
	//CLANG_PROFILE;
	r = dbt5_sql_execute(query, &result, "GET_USERS");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		bid = atol(dbt5_sql_getvalue(&result, 0, length));
		val = dbt5_sql_getvalue(&result, 1, length);
		user_name.assign(val);
		dbt5_sql_close_cursor(&result);
	}else{
		FAIL_MSG("GET_USER FAIL");
	}


	if(double(rand()%128)/128.0 < HIGHER_BID_THRESHOLD)
					bid_price = cur_price + double(rand()%16)/16.0;
	else
					bid_price = cur_price - double(rand()%128)/128.0;


	if(bid_price > cur_price){
		BIDDING_UPDATE_ITEM;
	}

	BIDDING_UPDATE_USER;

	BIDDING_INSERT_REC;

#else

	sprintf(query, GET_USER, pIn->user_id);
	//CLANG_PROFILE;
	r = dbt5_sql_execute(query, &result, "GET_USERS");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		bid = atol(dbt5_sql_getvalue(&result, 0, length));
		val = dbt5_sql_getvalue(&result, 1, length);
		user_name.assign(val);
		dbt5_sql_close_cursor(&result);
	}else{
		FAIL_MSG("GET_USER FAIL");
	}

	BIDDING_UPDATE_USER;

	sprintf(query, SELECT_ITEM, pIn->item_id);
	//CLANG_PROFILE;
	r = dbt5_sql_execute(query, &result, "GET_ITEM");
	if(r==1 && result.result_set){
		dbt5_sql_fetchrow(&result);
		cur_price = atof(dbt5_sql_getvalue(&result, 0, length));
		val = dbt5_sql_getvalue(&result, 1, length);
		item_description.assign(val);
		dbt5_sql_close_cursor(&result);
	}else{
		FAIL_MSG("GET_ITEM FAIL");
	}


	BIDDING_INSERT_REC;
	if(bid_price > cur_price){
		BIDDING_UPDATE_ITEM;
	}
#endif

}
Ejemplo n.º 19
0
void test_random_perms()
{

    for(int i = 0; i < 5; ++i)
    {
        options_t options;
        std::vector<std::string> args;
        args.push_back("osm2pgsql");

        //pick a projection
        options.projection.reset(reprojection::create_projection(get_random_proj(args)));

        //pick a style file
        std::string style = get_random_string(15);
        options.style = style.c_str();
        args.push_back("--style");
        args.push_back(style);

        add_arg_and_val_or_not("--cache", args, options.cache, rand() % 800);
        add_arg_and_val_or_not("--database", args, options.database_options.db.c_str(), get_random_string(6));
        if (options.database_options.username) {
            add_arg_and_val_or_not("--username", args, options.database_options.username->c_str(), get_random_string(6));
        }
        if (options.database_options.host) {
            add_arg_and_val_or_not("--host", args, options.database_options.host->c_str(), get_random_string(6));
        }
        //add_arg_and_val_or_not("--port", args, options.port, rand() % 9999);

        //--hstore-match-only
        //--hstore-column   Add an additional hstore (key/value) column containing all tags that start with the specified string, eg --hstore-column "name:" will produce an extra hstore column that contains all name:xx tags

        add_arg_or_not("--hstore-add-index", args, options.enable_hstore_index);

        //--tablespace-index    The name of the PostgreSQL tablespace where all indexes will be created. The following options allow more fine-grained control:
        //      --tablespace-main-data    tablespace for main tables
        //      --tablespace-main-index   tablespace for main table indexes
        //      --tablespace-slim-data    tablespace for slim mode tables
        //      --tablespace-slim-index   tablespace for slim mode indexes
        //                    (if unset, use db's default; -i is equivalent to setting
        //                    --tablespace-main-index and --tablespace-slim-index)

        add_arg_and_val_or_not("--number-processes", args, options.num_procs, rand() % 12);

        //add_arg_or_not("--disable-parallel-indexing", args, options.parallel_indexing);

        add_arg_or_not("--unlogged", args, options.unlogged);

        //--cache-strategy  Specifies the method used to cache nodes in ram. Available options are: dense chunk sparse optimized

        if (options.flat_node_file) {
            add_arg_and_val_or_not("--flat-nodes", args, options.flat_node_file->c_str(), get_random_string(15));
        }

        //--expire-tiles [min_zoom-]max_zoom    Create a tile expiry list.

        add_arg_and_val_or_not("--expire-output", args, options.expire_tiles_filename.c_str(), get_random_string(15));

        //--bbox        Apply a bounding box filter on the imported data Must be specified as: minlon,minlat,maxlon,maxlat e.g. --bbox -0.5,51.25,0.5,51.75

        add_arg_and_val_or_not("--prefix", args, options.prefix.c_str(), get_random_string(15));

        //--input-reader    Input frontend. auto, o5m, xml, pbf

        if (options.tag_transform_script) {
            add_arg_and_val_or_not("--tag-transform-script", args, options.tag_transform_script->c_str(), get_random_string(15));
        }
        add_arg_or_not("--extra-attributes", args, options.extra_attributes);
        add_arg_or_not("--multi-geometry", args, options.enable_multi);
        add_arg_or_not("--keep-coastlines", args, options.keep_coastlines);
        add_arg_or_not("--exclude-invalid-polygon", args, options.excludepoly);

        //add the input file
        args.push_back("tests/liechtenstein-2013-08-03.osm.pbf");

        const char** argv = new const char*[args.size() + 1];
        argv[args.size()] = nullptr;
        for(std::vector<std::string>::const_iterator arg = args.begin(); arg != args.end(); ++arg)
            argv[arg - args.begin()] = arg->c_str();
        options_t((int) args.size(), const_cast<char **>(argv));
        delete[] argv;
    }
}
Ejemplo n.º 20
0
static void
test_employee (void)
{
    QofBackend *be;
    QofBook *book;
    QofSession *session;
    GncEmployee *employee;

    session = qof_session_new();
    qof_session_begin(session, QOF_STDOUT, FALSE, FALSE);
    book = qof_session_get_book(session);
    /* The book *must* have a backend to pass the test of the 'dirty' flag */
    /* See the README file for details */

    be = qof_book_get_backend (book);

    /* Test creation/destruction */
    {
        do_test (gncEmployeeCreate (NULL) == NULL, "employee create NULL");
        employee = gncEmployeeCreate (book);
        do_test (employee != NULL, "employee create");
        do_test (qof_instance_get_book(QOF_INSTANCE(employee)) == book,
                 "getbook");

        gncEmployeeBeginEdit (employee);
        gncEmployeeDestroy (employee);
        success ("create/destroy");
    }

    /* Test setting/getting routines; does the active flag get set right? */
    {
        GncGUID guid;

        test_string_fcn (book, "Id", gncEmployeeSetID, gncEmployeeGetID);
        test_string_fcn (book, "Username", gncEmployeeSetUsername, gncEmployeeGetUsername);
        test_string_fcn (book, "Language", gncEmployeeSetLanguage, gncEmployeeGetLanguage);
        test_string_fcn (book, "Acl", gncEmployeeSetAcl, gncEmployeeGetAcl);

        test_numeric_fcn (book, "Workday", gncEmployeeSetWorkday, gncEmployeeGetWorkday);
        test_numeric_fcn (book, "Rate", gncEmployeeSetRate, gncEmployeeGetRate);

        test_bool_fcn (book, "Active", gncEmployeeSetActive, gncEmployeeGetActive);

        do_test (gncEmployeeGetAddr (employee) != NULL, "Addr");

        guid_new (&guid);
        employee = gncEmployeeCreate (book);
        count++;
        gncEmployeeSetGUID (employee, &guid);
        do_test (guid_equal (&guid, qof_instance_get_guid(QOF_INSTANCE(employee))), "guid compare");
    }
#if 0
    {
        GList *list;

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, TRUE);
        do_test (list != NULL, "getList all");
        do_test (g_list_length (list) == count, "correct length: all");
        g_list_free (list);

        list = gncBusinessGetList (book, GNC_EMPLOYEE_MODULE_NAME, FALSE);
        do_test (list != NULL, "getList active");
        do_test (g_list_length (list) == 1, "correct length: active");
        g_list_free (list);
    }
#endif
    {
        const char *str = get_random_string();
        const char *res;
        GncAddress *addr;

        addr = gncEmployeeGetAddr (employee);
        gncAddressSetName (addr, str);
        res = qof_object_printable (GNC_ID_EMPLOYEE, employee);
        do_test (res != NULL, "Printable NULL?");
        do_test (safe_strcmp (str, res) == 0, "Printable equals");
    }
}
    TEST_FIXTURE(file_directory_test_base, directory_list_files_and_directories)
    {
        m_directory.create_if_not_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);

        azure::storage::list_file_and_diretory_result_iterator end_of_list;
        for (auto iter = m_share.get_root_directory_reference().list_files_and_directories(); iter != end_of_list; ++iter)
        {
            CHECK_EQUAL(iter->is_directory(), true);
            CHECK_EQUAL(iter->is_file(), false);
            auto directory = iter->as_directory();

            check_equal(directory, m_directory);

            CHECK(directory.get_parent_share_reference().is_valid());
            check_equal(m_share, directory.get_parent_share_reference());

            CHECK(!directory.uri().primary_uri().is_empty());
            CHECK(directory.metadata().empty());
            CHECK(directory.properties().etag().empty());

            CHECK(!directory.properties().last_modified().is_initialized());
        }

        // more complicated file structure.
        const size_t size = 2;
        std::vector<utility::string_t> directories;
        std::vector<utility::string_t> files;
        for (size_t i = 0; i < size; ++i)
        {
            directories.push_back(_XPLATSTR("directory") + get_random_string(10));
        }
        for (size_t i = 0; i < size; ++i)
        {
            files.push_back(_XPLATSTR("file") + get_random_string(10));
        }
        for (size_t i = 0; i < size; ++i)
        {
            auto directory = m_share.get_directory_reference(directories[i]);
            directory.create_if_not_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);

            for (size_t j = 0; j < size; ++j)
            {
                auto subdirectory = directory.get_subdirectory_reference(directories[j]);
                subdirectory.create_if_not_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
                for (size_t k = 0; k < size; ++k)
                {
                    auto file = subdirectory.get_file_reference(files[k]);
                    file.create_if_not_exists(512U, azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
                }
            }
            for (size_t j = 0; j < size; ++j)
            {
                auto file = directory.get_file_reference(files[j]);
                file.create_if_not_exists(512U, azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
            }
            auto file = m_share.get_root_directory_reference().get_file_reference(files[i]);
            file.create_if_not_exists(512U, azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);
        }

        auto direcotries_one = directories;
        auto files_one = files;
        for (auto iter = m_share.get_root_directory_reference().list_files_and_directories(); iter != end_of_list; ++iter)
        {
            if (iter->is_directory())
            {
                auto directory2 = iter->as_directory();
                CHECK(directory2.get_parent_share_reference().is_valid());
                check_equal(m_share, directory2.get_parent_share_reference());
                CHECK(!directory2.uri().primary_uri().is_empty());
                CHECK(directory2.metadata().empty());
                CHECK(directory2.properties().etag().empty());
                CHECK(!directory2.properties().last_modified().is_initialized());

                auto found = false;
                for (auto directory_name = direcotries_one.begin(); directory_name != direcotries_one.end(); directory_name++)
                {
                    if (*directory_name == directory2.name())
                    {
                        direcotries_one.erase(directory_name);
                        found = true;
                        break;
                    }
                }

                auto direcotries_two = directories;
                auto files_two = files;
                for (auto iter2 = directory2.list_files_and_directories(); found && iter2 != end_of_list; ++iter2)
                {
                    if (iter2->is_directory())
                    {
                        auto directory3 = iter2->as_directory();
                        CHECK(directory3.get_parent_share_reference().is_valid());
                        check_equal(m_share, directory3.get_parent_share_reference());
                        CHECK(!directory3.uri().primary_uri().is_empty());
                        CHECK(directory3.metadata().empty());
                        CHECK(directory3.properties().etag().empty());
                        CHECK(!directory3.properties().last_modified().is_initialized());

                        for (auto directory_name = direcotries_two.begin(); directory_name != direcotries_two.end(); directory_name++)
                        {
                            if (*directory_name == directory3.name())
                            {
                                direcotries_two.erase(directory_name);
                                break;
                            }
                        }

                        auto files_three = files;
                        for (auto iter3 = directory3.list_files_and_directories(); iter3 != end_of_list; ++iter3)
                        {
                            CHECK(iter3->is_file());
                            auto file = iter3->as_file();
                            CHECK(file.get_parent_share_reference().is_valid());
                            check_equal(m_share, file.get_parent_share_reference());
                            CHECK(!file.uri().primary_uri().is_empty());
                            CHECK(file.metadata().empty());
                            CHECK(file.properties().etag().empty());
                            CHECK(!file.properties().last_modified().is_initialized());

                            for (auto file_name = files_three.begin(); file_name != files_three.end(); file_name++)
                            {
                                if (*file_name == file.name())
                                {
                                    files_three.erase(file_name);
                                    break;
                                }
                            }
                        }
                        CHECK(files_three.empty());
                    }
                    else if (iter2->is_file())
                    {
                        auto file = iter2->as_file();
                        CHECK(file.get_parent_share_reference().is_valid());
                        check_equal(m_share, file.get_parent_share_reference());
                        CHECK(!file.uri().primary_uri().is_empty());
                        CHECK(file.metadata().empty());
                        CHECK(file.properties().etag().empty());
                        CHECK(!file.properties().last_modified().is_initialized());

                        for (auto file_name = files_two.begin(); file_name != files_two.end(); file_name++)
                        {
                            if (*file_name == file.name())
                            {
                                files_two.erase(file_name);
                                break;
                            }
                        }
                    }

                }
                CHECK(!found || direcotries_two.empty());
                CHECK(!found || files_two.empty());
            }
            else if (iter->is_file())
            {
                auto file = iter->as_file();
                CHECK(file.get_parent_share_reference().is_valid());
                check_equal(m_share, file.get_parent_share_reference());
                CHECK(!file.uri().primary_uri().is_empty());
                CHECK(file.metadata().empty());
                CHECK(file.properties().etag().empty());
                CHECK(!file.properties().last_modified().is_initialized());

                for (auto file_name = files_one.begin(); file_name != files_one.end(); file_name++)
                {
                    if (*file_name == file.name())
                    {
                        files_one.erase(file_name);
                        break;
                    }
                }
            }
        }

        CHECK(direcotries_one.empty());
        CHECK(files_one.empty());
    }
Ejemplo n.º 22
0
void child_run(struct child_struct *child0, const char *loadfile)
{
	int i;
	char line[MAX_PARM_LEN], fname[MAX_PARM_LEN], fname2[MAX_PARM_LEN];
	char **sparams, **params;
	char *p;
	const char *status;
	gzFile *gzf;
	pid_t parent = getppid();
	double targett;
	struct child_struct *child;
	int have_random = 0;
	unsigned loop_count = 0;
	z_off_t loop_start = 0;

	gzf = gzopen(loadfile, "r");
	if (gzf == NULL) {
		perror(loadfile);
		exit(1);
	}

	for (child=child0;child<child0+options.clients_per_process;child++) {
		child->line = 0;
		asprintf(&child->cname,"client%d", child->id);
	}

	sparams = calloc(20, sizeof(char *));
	for (i=0;i<20;i++) {
		sparams[i] = malloc(MAX_PARM_LEN);
		memset(sparams[i], 0, MAX_PARM_LEN);
	}

again:
	for (child=child0;child<child0+options.clients_per_process;child++) {
		nb_time_reset(child);
	}

	while (gzgets(gzf, line, sizeof(line)-1)) {
		unsigned repeat_count = 1;

		for (child=child0;child<child0+options.clients_per_process;child++) {
			if (child->done) goto done;
			child->line++;
		}


		params = sparams;

		if (kill(parent, 0) == -1) {
			exit(1);
		}

loop_again:
		/* if this is a "LOOP <xxx>" line, 
		 * remember the current file position and move to the next line
		 */
		if (strncmp(line, "LOOP", 4) == 0) {
			if (sscanf(line, "LOOP %u\n", &loop_count) != 1) {
				fprintf(stderr, "Incorrect LOOP at line %d\n", child0->line);
				goto done;
			}

	       		for (child=child0;child<child0+options.clients_per_process;child++) {
				child->line++;
			}
			loop_start = gztell(gzf);
			gzgets(gzf, line, sizeof(line)-1);
			goto loop_again;
	        }

		if (strncmp(line, "ENDLOOP", 7) == 0) {
			loop_count--;

			gzgets(gzf, line, sizeof(line)-1);

			if (loop_count > 0) {
				gzseek(gzf, loop_start, SEEK_SET);
			}
			
			gzgets(gzf, line, sizeof(line)-1);
			goto loop_again;
		}			

		/* if this is a "REPEAT <xxx>" line, just replace the
		 * currently read line with the next line
		 */
		if (strncmp(line, "REPEAT", 6) == 0) {
			if (sscanf(line, "REPEAT %u\n", &repeat_count) != 1) {
				fprintf(stderr, "Incorrect REPEAT at line %d\n", child0->line);
				goto done;
			}

	       		for (child=child0;child<child0+options.clients_per_process;child++) {
				child->line++;
			}
			gzgets(gzf, line, sizeof(line)-1);
	        }


		/* WRITEPATTERN */
		if (strncmp(line, "WRITEPATTERN", 12) == 0) {
			char *ptr = rw_buf;
			int count = RWBUFSIZE;
			
			while (count > 0) {
			      int len;

			      len = count;
			      if (len > strlen(line +13)) {
			     	      len = strlen(line +13);
			      }
			      memcpy(ptr, line+13, len);
			      ptr += len;
			      count -= len;
			}
			goto again;
		}


		/* RANDOMSTRING */
		if (strncmp(line, "RANDOMSTRING", 12) == 0) {
			have_random = 1;
			if (parse_randomstring(line) != 0) {
				fprintf(stderr, "Incorrect RANDOMSTRING at line %d\n", child0->line);
				goto done;
			}
			goto again;
		}


		line[strlen(line)-1] = 0;

		all_string_sub(line,"\\", "/");
		all_string_sub(line," /", " ");

		/* substitute all $<digit> stored strings */
		while (have_random && (p = index(line, '$')) != NULL) {
			char sstr[3], *nstr;
			unsigned int idx;
		      
		      	idx = *(p+1) - '0';
			if (idx >= MAX_RND_STR) {
				fprintf(stderr, "$%d is an invalid filename/string\n", idx);
				goto done;
			}

			sstr[0] = '$';
			sstr[1] = idx+'0';
			sstr[2] = '\0';

			nstr = get_random_string(idx);
			all_string_sub(line, sstr, nstr);
		}
		
		p = line;
		for (i=0; 
		     i<19 && next_token(&p, params[i], " ");
		     i++) ;

		params[i][0] = 0;

		if (i < 2 || params[0][0] == '#') continue;

		if (!strncmp(params[0],"SMB", 3)) {
			printf("ERROR: You are using a dbench 1 load file\n");
			exit(1);
		}

		if (i > 0 && isdigit(params[0][0])) {
			targett = strtod(params[0], NULL);
			params++;
			i--;
		} else {
			targett = 0.0;
		}

		if (strncmp(params[i-1], "NT_STATUS_", 10) != 0 &&
		    strncmp(params[i-1], "0x", 2) != 0 &&
		    strncmp(params[i-1], "SUCCESS", 7) != 0 &&
		    strncmp(params[i-1], "ERROR", 7) != 0 &&
		    strncmp(params[i-1], "*", 1) != 0) {
			printf("Badly formed status at line %d\n", child->line);
			continue;
		}

		status = params[i-1];

		
		for (child=child0;child<child0+options.clients_per_process;child++) {
			unsigned child_repeat_count = repeat_count;
			int pcount = 1;

			fname[0] = 0;
			fname2[0] = 0;

			if (i>1 && params[1][0] == '/') {
				snprintf(fname, sizeof(fname), "%s%s", child->directory, params[1]);
				all_string_sub(fname,"client1", child->cname);
				pcount++;
			}
			if (i>2 && params[2][0] == '/') {
				snprintf(fname2, sizeof(fname2), "%s%s", child->directory, params[2]);
				all_string_sub(fname2,"client1", child->cname);
				pcount++;
			}

			if (options.targetrate != 0 || targett == 0.0) {
				nb_target_rate(child, options.targetrate);
			} else {
				nb_time_delay(child, targett);
			}
			while (child_repeat_count--) {
				child_op(child, params[0], fname, fname2, params+pcount, status);
			}
		}
	}

	if (options.run_once) {
		goto done;
	}

	gzrewind(gzf);
	goto again;

done:
	gzclose(gzf);
	for (child=child0;child<child0+options.clients_per_process;child++) {
		child->cleanup = 1;
		fflush(stdout);
		if (!options.skip_cleanup) {
			nb_ops->cleanup(child);
		}
		child->cleanup_finished = 1;
		if(child->cname){
			free(child->cname);
			child->cname = NULL;
		}
	}
}
    TEST_FIXTURE(file_directory_test_base, directory_list_files_and_directories_with_prefix)
    {
        m_directory.create_if_not_exists(azure::storage::file_access_condition(), azure::storage::file_request_options(), m_context);

        auto prefix = _XPLATSTR("t") + get_random_string(3);
        auto dir_prefix = prefix + _XPLATSTR("dir");
        auto file_prefix = prefix + _XPLATSTR("file");
        auto exclude_prefix = _XPLATSTR("exclude");

        std::vector<azure::storage::cloud_file_directory> directories;
        std::vector<azure::storage::cloud_file> files;
        for (int i = 0; i < get_random_int32() % 3 + 1; ++i)
        {
            auto subdirectory = m_directory.get_subdirectory_reference(dir_prefix + utility::conversions::print_string(i));
            subdirectory.create();
            directories.push_back(subdirectory);

            auto file = m_directory.get_file_reference(file_prefix + utility::conversions::print_string(i));
            file.create(1);
            files.push_back(file);

            m_directory.get_subdirectory_reference(exclude_prefix + utility::conversions::print_string(i)).create();
        }

        int num_items_expected = directories.size() + files.size();
        int num_items_actual = 0;
        for (auto&& item : m_directory.list_files_and_directories(prefix))
        {
            ++num_items_actual;
            if (item.is_directory())
            {
                auto actual = item.as_directory();
                CHECK(actual.get_parent_share_reference().is_valid());
                check_equal(m_share, actual.get_parent_share_reference());
                
                auto it_found = std::find_if(directories.begin(), directories.end(), [&actual](const azure::storage::cloud_file_directory& expect)
                {
                    return actual.name() == expect.name();
                });
                CHECK(it_found != directories.end());
                check_equal(*it_found, actual);
                directories.erase(it_found);
            }
            else if (item.is_file())
            {
                auto actual = item.as_file();
                CHECK(actual.get_parent_share_reference().is_valid());
                check_equal(m_share, actual.get_parent_share_reference());

                auto it_found = std::find_if(files.begin(), files.end(), [&actual](const azure::storage::cloud_file& expect)
                {
                    return actual.name() == expect.name();
                });
                CHECK(it_found != files.end());
                check_equal(*it_found, actual);
                files.erase(it_found);
            }
        }

        CHECK_EQUAL(num_items_expected, num_items_actual);
        CHECK(directories.empty());
        CHECK(files.empty());
    }