Esempio n. 1
0
int main(int argc, char **argv)
{
  char *srcdir = getenv("srcdir");
  char out_path[L_tmpnam];
  FILE *out = fopen(tmpnam(out_path), "w");
  char *expected_path;

  if (out == NULL)
    die("opening %s: %s", out_path, strerror(errno));

  test_table_codec(out);
  fprintf(out, "----------\n");
  test_dump_value(out);

  fclose(out);

  if (srcdir == NULL)
    die("'srcdir' environment variable not defined");

  expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2);
  sprintf(expected_path, "%s/%s", srcdir, expected_file_name);
  if (compare_files(expected_path, out_path))
    die("output file did not have expected contents; see %s", out_path);

  if (remove(out_path))
    die("deleting %s: %s", out_path, strerror(errno));

  return 0;
}
Esempio n. 2
0
int main(void)
{
  char *srcdir = getenv("srcdir");
  FILE *out, *expected = NULL;
  char *expected_path;

  out = tmpfile();
  if (out == NULL) {
    die("failed to create temporary file: %s", strerror(errno));
  }

  test_table_codec(out);
  fprintf(out, "----------\n");
  test_dump_value(out);

  if (srcdir == NULL) {
    srcdir = ".";
  }

  expected_path = malloc(strlen(srcdir) + strlen(expected_file_name) + 2);
  sprintf(expected_path, "%s/%s", srcdir, expected_file_name);
  expected = fopen(expected_path, "r");
  if (!expected) {
    die("failed to open %s: %s", expected_path, strerror(errno));
  }

  if (compare_files(expected, out)) {
    die("output file did not have expected contents");
  }

  fclose(out);
  fclose(expected);

  return 0;
}
Esempio n. 3
0
int main(int argc, char const * const *argv) {
  amqp_table_entry_t entries[8];
  amqp_table_t table;

  union {
    uint32_t i;
    float f;
  } vi;
  union {
    uint64_t l;
    double d;
  } vl;

  entries[0].key = amqp_cstring_bytes("zebra");
  entries[0].value.kind = AMQP_FIELD_KIND_UTF8;
  entries[0].value.value.bytes = amqp_cstring_bytes("last");

  entries[1].key = amqp_cstring_bytes("aardvark");
  entries[1].value.kind = AMQP_FIELD_KIND_UTF8;
  entries[1].value.value.bytes = amqp_cstring_bytes("first");

  entries[2].key = amqp_cstring_bytes("middle");
  entries[2].value.kind = AMQP_FIELD_KIND_UTF8;
  entries[2].value.value.bytes = amqp_cstring_bytes("third");

  entries[3].key = amqp_cstring_bytes("number");
  entries[3].value.kind = AMQP_FIELD_KIND_I32;
  entries[3].value.value.i32 = 1234;

  entries[4].key = amqp_cstring_bytes("decimal");
  entries[4].value.kind = AMQP_FIELD_KIND_DECIMAL;
  entries[4].value.value.decimal.decimals = 2;
  entries[4].value.value.decimal.value = 1234;

  entries[5].key = amqp_cstring_bytes("time");
  entries[5].value.kind = AMQP_FIELD_KIND_TIMESTAMP;
  entries[5].value.value.u64 = 1234123412341234;

  entries[6].key = amqp_cstring_bytes("beta");
  entries[6].value.kind = AMQP_FIELD_KIND_UTF8;
  entries[6].value.value.bytes = amqp_cstring_bytes("second");

  entries[7].key = amqp_cstring_bytes("wombat");
  entries[7].value.kind = AMQP_FIELD_KIND_UTF8;
  entries[7].value.value.bytes = amqp_cstring_bytes("fourth");

  table.num_entries = 8;
  table.entries = entries;

  vi.f = M_PI;
  if ((sizeof(float) != 4) || (vi.i != 0x40490fdb)) {
    printf("*** ERROR: single floating point encoding does not work as expected\n");
    printf("sizeof float is %lu, float is %g, u32 is 0x%08lx\n",
	   (unsigned long)sizeof(float),
	   vi.f,
	   (unsigned long) vi.i);
  }

  vl.d = M_PI;
  if ((sizeof(double) != 8) || (vl.l != 0x400921fb54442d18L)) {
    printf("*** ERROR: double floating point encoding does not work as expected\n");
    printf("sizeof double is %lu, double is %g, u64 is 0x%16"PRIx64"\n",
	   (unsigned long)sizeof(double),
	   vl.d, vl.l);
  }

  test_table_codec();

  qsort(table.entries, table.num_entries, sizeof(amqp_table_entry_t), &amqp_table_entry_cmp);

  printf("----------\n");

  {
    amqp_field_value_t val;
    val.kind = AMQP_FIELD_KIND_TABLE;
    val.value.table = table;

    dump_value(0, val);
  }

  return 0;
}