diff options
Diffstat (limited to 'test/utils.cpp')
| -rw-r--r-- | test/utils.cpp | 63 |
1 files changed, 11 insertions, 52 deletions
diff --git a/test/utils.cpp b/test/utils.cpp index c1619a9..1a60045 100644 --- a/test/utils.cpp +++ b/test/utils.cpp @@ -1,22 +1,19 @@ - - #include <string> #include <stdlib.h> #include <iostream> -#include <type_traits> #include <vector> -#include <functional> #include <chrono> #include <random> -#include <tuple> #include <string.h> #include <algorithm> + #include "fieldstat.h" #include "utils.hpp" using namespace std; + string gen_rand_string(int len) { char cstr[len + 1]; @@ -33,13 +30,13 @@ string gen_rand_string(int len) /* taglist wrapper */ /* -------------------------------------------------------------------------- */ -Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct fieldstat_tag_group *tag_list) { +Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct fieldstat_tag_list *tag_list) { tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_list->n_tag); tag_list_c.n_tag = tag_list->n_tag; for (size_t i = 0; i < tag_list->n_tag; i++) { // copy the tag_list - memcpy((char *)tag_list_c.tag[i].key, tag_list->tag[i].key, MAX_TAG_KEY_LENGTH); + tag_list_c.tag[i].key = strdup(tag_list->tag[i].key); tag_list_c.tag[i].type = tag_list->tag[i].type; switch (tag_list->tag[i].type) { @@ -50,7 +47,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const struct fieldstat_ta tag_list_c.tag[i].value_double = tag_list->tag[i].value_double; break; case TAG_CSTRING: - memcpy((char *)tag_list_c.tag[i].value_str, tag_list->tag[i].value_str, MAX_TAG_STRING_VAL_LENGTH); + tag_list_c.tag[i].value_str = strdup(tag_list->tag[i].value_str); break; default: break; @@ -66,7 +63,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(std::uniform_int_distribu { tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_count); tag_list_c.n_tag = tag_count; - std::mt19937 rng(RAND_SEED); + std::mt19937 rng(1); for (int i = 0; i < tag_count; i++) { strcpy((char *)tag_list_c.tag[i].key, gen_rand_string(10).c_str()); @@ -95,13 +92,13 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper() { } Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const Fieldstat_tag_list_wrapper &tag_list_wrapper){ - const struct fieldstat_tag_group *tag_list = tag_list_wrapper.get_c_struct(); + const struct fieldstat_tag_list *tag_list = tag_list_wrapper.get_c_struct(); tag_list_c.tag = (struct fieldstat_tag *)malloc(sizeof(struct fieldstat_tag) * tag_list->n_tag); tag_list_c.n_tag = tag_list->n_tag; for (size_t i = 0; i < tag_list->n_tag; i++) { // copy the tag_list - memcpy((char *)tag_list_c.tag[i].key, tag_list->tag[i].key, MAX_TAG_KEY_LENGTH); + tag_list_c.tag[i].key = strdup(tag_list->tag[i].key); tag_list_c.tag[i].type = tag_list->tag[i].type; switch (tag_list->tag[i].type) { @@ -112,7 +109,7 @@ Fieldstat_tag_list_wrapper::Fieldstat_tag_list_wrapper(const Fieldstat_tag_list_ tag_list_c.tag[i].value_double = tag_list->tag[i].value_double; break; case TAG_CSTRING: - memcpy((char *)tag_list_c.tag[i].value_str, tag_list->tag[i].value_str, MAX_TAG_STRING_VAL_LENGTH); + tag_list_c.tag[i].value_str = strdup(tag_list->tag[i].value_str); break; default: break; @@ -130,7 +127,7 @@ size_t Fieldstat_tag_list_wrapper::get_tag_count() const return tag_list_c.n_tag; } -const struct fieldstat_tag_group *Fieldstat_tag_list_wrapper::get_c_struct() const +const struct fieldstat_tag_list *Fieldstat_tag_list_wrapper::get_c_struct() const { return &tag_list_c; } @@ -162,7 +159,7 @@ void Fieldstat_tag_list_wrapper::print_tag_list() const bool Fieldstat_tag_list_wrapper::operator==(const Fieldstat_tag_list_wrapper &tag_list_wrapper) const { - const struct fieldstat_tag_group *tag_list = tag_list_wrapper.get_c_struct(); + const struct fieldstat_tag_list *tag_list = tag_list_wrapper.get_c_struct(); if (tag_list_c.n_tag != tag_list->n_tag) { return false; } @@ -194,42 +191,4 @@ bool Fieldstat_tag_list_wrapper::operator==(const Fieldstat_tag_list_wrapper &ta } } return true; -} - -struct fieldstat *test_serialize_and_deserialize(struct fieldstat *instance) -{ - // serialize - char *blob = NULL; - size_t blob_size = 0; - fieldstat_serialize(instance, &blob, &blob_size); - // deserialize - struct fieldstat *instance_from_deserialize = fieldstat_deserialize(blob, blob_size); - free(blob); - return instance_from_deserialize; -} - -void test_merge_with_blob(struct fieldstat *dest, const struct fieldstat *src) -{ - char *blob = NULL; - size_t blob_size = 0; - fieldstat_serialize(src, &blob, &blob_size); - fieldstat_merge_with_blob(dest, blob, blob_size); - free(blob); -} - -void test_merge_with_blob_twice(struct fieldstat *dest, const struct fieldstat *src) -{ - char *blob = NULL; - size_t blob_size = 0; - fieldstat_serialize(src, &blob, &blob_size); - fieldstat_merge_with_blob(dest, blob, blob_size); - fieldstat_merge_with_blob(dest, blob, blob_size); - free(blob); -} - -void test_hll_add(int adding_time, struct fieldstat *instance, int id, const struct fieldstat_tag *tags, size_t tag_count) { - for (int i = 0; i < adding_time; i++) { - std::string tmp_str = to_string(i); - fieldstat_hll_add(instance, id, tmp_str.c_str(), tmp_str.size(), tags, tag_count); - } }
\ No newline at end of file |
