Exemple #1
0
static void
test_base64_encode_(const TEST_VECTOR* vectors, const BASE64_OPTIONS* options)
{
    char out_buf[256];
    int i;

    for(i = 0; vectors[i].blob != NULL; i++) {
        const char* blob = vectors[i].blob;
        const char* base64 = vectors[i].base64;
        int out_size;

        out_size = base64_encode(blob, strlen(blob), NULL, 0, options);
        if(!TEST_CHECK_(out_size >= 0  &&
                        out_size == strlen(base64)+1,
                        "expected output size for '%s' -> '%s'", blob, base64))
        {
            TEST_MSG("Expected: %d bytes", (int) strlen(base64));
            TEST_MSG("Produced: %d bytes", (int) out_size);
        }

        out_size = base64_encode(blob, strlen(blob), out_buf, sizeof(out_buf), options);
        if(!TEST_CHECK_(out_size >= 0  &&
                        out_size == strlen(base64)  &&
                        memcmp(out_buf, base64, out_size) == 0,
                        "encoding '%s' -> %s", blob, base64))
        {
            TEST_MSG("Expected: '%s'", base64);
            TEST_MSG("Produced: '%s'", (out_size > 0 ? out_buf : "base64_encode() failed"));
        }
    }
}
Exemple #2
0
void test_pass_array(void)
{
  char* list[3];
  list[0] = "item1";
  list[1] = "item2";
  list[2] = NULL;
  pass_array((char**)list);
  TEST_CHECK_((1==1),"ok");
}
Exemple #3
0
void test_pack_payload()
{
    uint8_t payload[] = { 0x78, 0x46, 0x02 };
    uint8_t *result = NULL;
    unsigned int length = 3;

    uint16_t total_length;

    total_length = pack_payload(payload, &result, length);
    TEST_CHECK_(result != NULL, "Result doesn't point to anything");
    TEST_CHECK_(total_length == 9, "Incorrect length: %d", total_length);
    TEST_CHECK(result[0] == 0x02);
    TEST_CHECK(result[8] == 0x03);
    TEST_CHECK_(result[1] == 3, "Incorrect LSB length: %d", result[1]);
    TEST_CHECK_(result[2] == 0, "Incorrect MSB length: %d", result[2]);
    TEST_CHECK_(result[6] == 0x3C, "Incorrect LRC: %#x", result[6]);
    TEST_CHECK_(result[7] == 0xC0, "Incorrect checksum:  %#x", result[7]);

    free(result);
}
Exemple #4
0
void test_pack_payload2()
{
    uint8_t payload[] = {
        0x06, 0x35, 0x33, 0x39, 0x54, 0x30, 0x39, 0x34, 0x35, 0x38, 0x32
    };
    uint8_t *result = NULL;
    unsigned int length = 11;
    uint16_t total_length;

    total_length = pack_payload(payload, &result, length);

    TEST_CHECK_(result != NULL, "Result doesn't point to anything");
    TEST_CHECK_(total_length == 17, "Incorrect length: %d", total_length);
    TEST_CHECK(result[0] == 0x02);
    TEST_CHECK(result[total_length - 1] == 0x03);
    TEST_CHECK_(result[1] == 0x0B, "Incorrect LSB length: %d", result[1]);
    TEST_CHECK_(result[2] == 0, "Incorrect MSB length: %d", result[2]);
    TEST_CHECK_(result[total_length - 3] == 0x6F, "Incorrect LRC: %#x", result[total_length - 3]);
    TEST_CHECK_(result[total_length - 2] == 0x37, "Incorrect checksum:  %#x", result[total_length - 2]);

    free(result);
}
Exemple #5
0
void test_hello_world(void)
{
    printf("Hello World");
    TEST_CHECK_((1 != 0 ),"1 should be equal to 0 !");
}
Exemple #6
0
void test_multiply(void)
{
    int num = 2;
    int result = multiply_by_two(num);
    TEST_CHECK_((result == num*2),"ok");
}
Exemple #7
0
void test_colon(void) {
  test_setup();

  printf("\n<<<<<<<<<<<< TEST ':' <<<<<<<<<<<< \n\n");

  printf("ctx->rsp: %p\n", ctx_rsp);
  printf("ctx->psp: %p\n", ctx_psp);
  printf("ctx->vars: %p\n", ctx_vars);
  printf("ctx->regs: %p\n", ctx_regs);

  // Vars
  int i, n;
  fcell_xt* var[50] = {0};

  i = 0; n = 15;
  for (int j = 0; j < n; j++)
    var[j] = forth_alloc_var();

  fword_t *entry_colon = dict_find(1, ":");
  printf("colon: `:` %p \n", entry_colon);
  TEST_CHECK_(entry_colon != NULL, "Expected non-null `:` word, got "CELL_FMT"", entry_colon);
  printf("colon cfa: `:` %p\n", dict_cfa(entry_colon));
  printf("xt_colon: `:` %p -> %p \n", xt_colon, *xt_colon);

  int idx_interpret = i;
  *var[i++] = (fcell_xt) dict_cfa(dict_find(7, "docolon"));
  *var[i++] = (fcell_xt) dict_cfa(dict_find(9, "interpret"));
  *var[i++] = dict_cfa(dict_find(4, "semi"));
  (void)idx_interpret;

  ctx_vars->tib_str = " : a 0x99 ;";
  ctx_vars->tib_len = strlen(ctx_vars->tib_str);
  ctx_vars->tib_idx = 0;

  forth_eval(var[0]);
  forth_flush_tob();

  dict_print();
  // Try running new word!


  fword_t *entry_a = dict_find(1, "a");
  TEST_CHECK_(entry_a != NULL, "Expected non-null `:` word, got %p for %s", entry_a, "entry_a");
  printf("entry_a: %p\n", entry_a);

  fcell_xt * cfa_a = (fcell_xt *) dict_cfa(entry_a);
  TEST_CHECK_(cfa_a != NULL, "Expected non-null `:` word, got "CELL_FMT" for %s", cfa_a, "cfa_a");

  printf("cfa_aa: %p\n", cfa_a);

  fword_t *semicolon = dict_find(1, ";");
  printf("semicolon: %p\n", semicolon);

  fcell_t expi;
  fcell_t expl;
  fcell_t cnt;
  fcell_t x;
  fcell_t err;

  // Good Case
  ctx_vars->tib_str = "a 1 +";
  ctx_vars->tib_len = 5;
  ctx_vars->tib_idx = 0;

  forth_eval(var[0]);
  forth_flush_tob();

  expi = 154;
  expl = 1;

  cnt = forth_count();
  TEST_CHECK_(cnt == expl, "Expected "CELL_FMT", got "CELL_FMT"", expl, cnt);
  x = forth_pop();
  TEST_CHECK_(x == expi, "Expected "CELL_FMT", got "CELL_FMT"", expi, x);

  err = forth_errno();
  TEST_CHECK_(err == FW_OK, "Expected "CELL_FMT", got "CELL_FMT"", FW_OK, err);

  // Bad Case
  ctx_vars->tib_str = "b 1 +";
  ctx_vars->tib_len = 5;
  ctx_vars->tib_idx = 0;

  forth_eval(var[0]);
  forth_flush_tob();

  expi = 0;
  expl = 0;

  cnt = forth_count();
  TEST_CHECK_(cnt == expl, "Expected "CELL_FMT", got "CELL_FMT"", expl, cnt);

  err = forth_errno();
  TEST_CHECK_(err == FW_ERR_NOWORD, "Expected "CELL_FMT", got "CELL_FMT"", FW_ERR_NOWORD, err);

}
Exemple #8
0
void test_interpreter(void) {
  test_setup();

  dict_print();
  fcell_t dlen = ctx_vars->tob_idx;
  printf("TOB SZ: %s\n", ctx_vars->tob_str);
  for (fcell_t i = 0; i < dlen; i++) {
    putchar(ctx_vars->tob_str[i]);
  }
  printf("TOB DONE\n");

  printf("ctx->rsp: %p\n", ctx_rsp);
  printf("ctx->psp: %p\n", ctx_psp);
  printf("ctx->vars: %p\n", ctx_vars);
  printf("ctx->regs: %p\n", ctx_regs);

  // Vars
  int i, n;
  fcell_xt* var[50] = {0};

  i = 0; n = 4;
  for (int j = 0; j < n; j++)
    var[j] = forth_alloc_var();

  // Colons
  *var[i++] = (fcell_xt) dict_cfa(dict_find(7, "docolon"));
  *var[i++] = (fcell_xt) dict_cfa(dict_find(9, "interpret"));
  *var[i++] = dict_cfa(dict_find(4, "semi"));

  ctx_vars->tib_str = "7 2 +";
  ctx_vars->tib_len = 5;
  ctx_vars->tib_idx = 0;

  forth_eval(var[0]);
  forth_flush_tob();

  print_psp_info();

  int cnt = forth_count();
  fcell_t x = forth_pop();
  TEST_CHECK_(1 == cnt, "Expected "CELL_FMT", got "CELL_FMT"", 1, cnt);

  print_stack(); printf("... stack done\n");

  TEST_CHECK_(x == 9, "Expected "CELL_FMT", got "CELL_FMT"", 9, x);

  x = forth_pop();
  cnt = forth_count();
  TEST_CHECK_(0 == cnt, "Expected "CELL_FMT", got "CELL_FMT"", 0, cnt);
  TEST_CHECK_(forth_errno() == FW_ERR_STACKUNDERFLOW,
              "Expected "CELL_FMT", got "CELL_FMT"",
              forth_errno(),
              FW_ERR_STACKUNDERFLOW);

  forth_clear();

  TEST_CHECK_(forth_errno() == FW_OK,
              "Expected "CELL_FMT", got "CELL_FMT"",
              forth_errno(),
              FW_OK);

  printf(" >>>>>>>>>>>>>> basic test \n\n\n");
}