Exemplo n.º 1
0
// A single string should be extractable.
static char* test_global_single_string(void) {
  data_processor_init("Hello", '|');
  ProcessingState* state = data_processor_get_global();
  const char* str = data_processor_get_string(state);
  mu_assert(strcmp(str, "Hello") == 0, "Single string not extracted from global state");
  return 0;
}
Exemplo n.º 2
0
int main(int argc,char ** argv) {
	const char *infile = "dump-raw-3.txt";
	const char *outfile = "test-output.txt";
	if (argc == 3) {
		infile = argv[1];
		outfile = argv[2];
	}
	float hz = 0;
	data_processor_t dfft = NULL;
	dfft = data_processor_init(2048, 214000);
	if (!dfft) {
		fprintf(stderr, "data_processor_init error\n");
		return -1;
	}

	read_data(infile, dfft->cin, dfft->nfft);

	int i = 100;
	while (i-- > 0) {
		hz = data_processor_run(dfft);
		printf("hz = %12f\n", hz);
	}

	write_data(outfile, dfft->cout, dfft->nfft);

	data_processor_close(dfft);
	dfft = NULL;
	return 0;
}
Exemplo n.º 3
0
static void handle_details(char* data) {
  free_safe(details);
  data_processor_init(data, '|');
  details = data_processor_get_string();
  if (details_handler) {
    details_handler(details);
  }
}
Exemplo n.º 4
0
// Multiple booleans should be extractable.
static char* test_global_multiple_booleans(void) {
  data_processor_init("1|0|", '|');
  bool boolean1 = data_processor_get_bool(data_processor_get_global());
  bool boolean2 = data_processor_get_bool(data_processor_get_global());
  bool boolean3 = data_processor_get_bool(data_processor_get_global());
  mu_assert(true == boolean1 && false == boolean2 && false == boolean3, "Multipe booleans not extracted from global state");
  return 0;
}
Exemplo n.º 5
0
// Mixed values should be extractable from the global state.
static char* test_global_mixed(void) {
  data_processor_init("8|This is a string!|0|6765444", '|');
  int num1 = data_processor_get_int(data_processor_get_global());
  char* string1 = data_processor_get_string(data_processor_get_global());
  bool boolean1 = data_processor_get_bool(data_processor_get_global());
  int num2 = data_processor_get_int(data_processor_get_global());
  mu_assert(8 == num1 && 0 == strcmp("This is a string!", string1) && false == boolean1 && 6765444 == num2, "Mixed values not extracted from global state");
  return 0;
}
Exemplo n.º 6
0
// Multiple numbers should be extractable.
static char* test_global_multiple_numbers(void) {
  data_processor_init("1|55555|0", '|');
  ProcessingState* state = data_processor_get_global();
  int num1 = data_processor_get_int(state);
  int num2 = data_processor_get_int(state);
  int num3 = data_processor_get_int(state);
  mu_assert(1 == num1 && 55555 == num2 && 0 == num3, "Multiple numbers not extracted from global state");
  return 0;
}
Exemplo n.º 7
0
// Mixed values should be simultaneously be extractable from the global and a local state.
static char* test_local_and_global_mixed(void) {
  ProcessingState* state1 = data_processor_create("8|This is a string!", '|');
  data_processor_init("0|6765444", '|');
  ProcessingState* state2 = data_processor_get_global();
  int num1 = data_processor_get_int(state1);
  bool boolean1 = data_processor_get_bool(state2);
  char* string1 = data_processor_get_string(state1);
  int num2 = data_processor_get_int(state2);
  mu_assert(8 == num1 && 0 == strcmp("This is a string!", string1) && false == boolean1 && 6765444 == num2, "Mixed values not extracted from global state");
  return 0;
}
Exemplo n.º 8
0
static void handle_update(char* data) {
  destroy_lines();

  data_processor_init(data, '|');
  num_lines = data_processor_get_int();
  lines = malloc(sizeof(TubeLine*) * num_lines);
  for (uint8_t l = 0; l < num_lines; l += 1) {
    TubeLine* line = malloc(sizeof(TubeLine));
    line->name = data_processor_get_string();
    line->status = data_processor_get_string();
    lines[l] = line;
  }
  update_handler();
}
Exemplo n.º 9
0
// Several strings separated by delimiter should be extractable.
static char* test_global_multiple_strings(void) {
  data_processor_init("Hello|Hi|Hey||", '|');
  ProcessingState* state = data_processor_get_global();
  const char* str1 = data_processor_get_string(state);
  const char* str2 = data_processor_get_string(state);
  const char* str3 = data_processor_get_string(state);
  const char* str4 = data_processor_get_string(state);
  const char* str5 = data_processor_get_string(state);
  bool pass = strcmp(str1, "Hello") == 0;
  pass = pass && strcmp(str2, "Hi") == 0;
  pass = pass && strcmp(str3, "Hey") == 0;
  pass = pass && strcmp(str4, "") == 0;
  pass = pass && strcmp(str5, "") == 0;
  mu_assert(pass, "Multiple strings not extracted from global state");
  return 0;
}
Exemplo n.º 10
0
/**
 * Function to process the data of a preset update.
 * @param data "DATA" response of the given message, formatted either
 * as "stop_id|stop_name|route_id|route_name", or as "END" to signify the end
 * of the preset messages.
 */
static void process_preset_data(char* data){
	if (strcmp(data, "END") != 0){
		data_processor_init(data, '|');
		Preset *preset = malloc(sizeof(Preset));
		strcpy(preset->stop_id, data_processor_get_string());
		strcpy(preset->stop_name, data_processor_get_string());
		strcpy(preset->route_id, data_processor_get_string());
		strcpy(preset->route_name, data_processor_get_string());
		preset->eta = -5;
		presets_add(preset);
	}
	else{
		send_all_eta_req();
		refresh();
		reset_selected_index();
		update_time_text();
	}
}
Exemplo n.º 11
0
/**
 * Function to process the data of an ETA update message.
 * @param data the "DATA" response of the given method, which is formatted as "stop_id|route_id|eta"
 */
static void process_eta_data(char* data){
	data_processor_init(data, '|');
	char* stop_id = data_processor_get_string();
	char* route_id = data_processor_get_string();
	char* eta_string = data_processor_get_string();
	int eta = PRESET_NO_ETA;
	if (strcmp(eta_string, "NO ETA") != 0){
		eta = atoi(eta_string);
	}
	for (int i = 0; i < presets_get_count(); i++){
		Preset *preset = presets_get(i);
		if (strcmp(preset->stop_id, stop_id) == 0 && strcmp(preset->route_id, route_id) == 0){
			preset->eta = eta;
			break;
		}
	}
	free(stop_id);
	free(route_id);
	refresh();
	update_time_text();
}
Exemplo n.º 12
0
// The count of multiple subelements should be equal to the number of subelements.
static char* test_count_multiple(void) {
  data_processor_init("Hello|Goodbye||", '|');
  int count = data_processor_count(data_processor_get_global());
  mu_assert(4 == count, "Count of multiple subelements not calculated correctly");
  return 0;
}
Exemplo n.º 13
0
// A single boolean should be extractable.
static char* test_global_single_boolean(void) {
  data_processor_init("1", '|');
  bool boolean = data_processor_get_bool(data_processor_get_global());
  mu_assert(true == boolean, "Single boolean not extracted from global state");
  return 0;
}
Exemplo n.º 14
0
// The count of a single subelement should be 1.
static char* test_count_single(void) {
  data_processor_init("Hello", '|');
  int count = data_processor_count(data_processor_get_global());
  mu_assert(1 == count, "Count of single subelement not calculated correctly");
  return 0;
}
Exemplo n.º 15
0
// A single number should be extractable.
static char* test_global_single_number(void) {
  data_processor_init("1", '|');
  int num = data_processor_get_int(data_processor_get_global());
  mu_assert(1 == num, "Single number not extracted from global state");
  return 0;
}
Exemplo n.º 16
0
// The count of an empty string should be 0.
static char* test_count_none(void) {
  data_processor_init("", '|');
  int count = data_processor_count(data_processor_get_global());
  mu_assert(0 == count, "Count of zero subelements not calculated correctly");
  return 0;
}
Exemplo n.º 17
0
// The global state object should be available after init.
static char* test_init(void) {
  data_processor_init("", '|');
  mu_assert(data_processor_get_global() != NULL, "Global state does not exist.");
  return 0;
}