示例#1
0
char *test_array_push()
{
    test_assert(Array_push(a, one) == 0, "Push one failed");
    test_assert(Array_push(a, two) == 0, "Push two failed");
    test_assert(Array_push(a, three) == 0, "Push three failed");

    test_assert(a->length == 3, "Wrong length after push");

    test_assert_streq(a->elements[0], one, "Wrong element: one");
    test_assert_streq(a->elements[1], two, "Wrong element: two");
    test_assert_streq(a->elements[2], three, "Wrong element: three");

    return NULL;
}
示例#2
0
文件: hash.c 项目: skarb/skarb
Object * Hash_keys(Object *self) {
    GList *keys_list = g_hash_table_get_keys(as_hash(self)->hash);
    Object *keys = Array_new();
    while (keys_list) {
        Array_push(keys, as_object(keys_list->data));
        keys_list = keys_list->next;
    }
    return keys;
}
char *test_push_pop()
{
  int i = 0;
  for(i = 0; i < 1000; i++) {
    int *val = Array_new(array);
    *val = i * 333;
    Array_push(array, val);
  }

  mu_assert(array->max == 1201, "Wrong max size.");

  for(i = 999; i >= 0; i--) {
    int *val = Array_pop(array);
    mu_assert(val != NULL, "Shouldn't get a NULL.");
    mu_assert(*val == i * 333, "Wrong value.");
    Array_free(val);
  }

  return NULL;
}
示例#4
0
文件: example.c 项目: xsoameix/libooc
int main(void) {
    // static string
    Value a;
    Value_type(&a, StaticString);
    Value_set_str(&a, "a");
    Value_get_str(&a);

    // string
    void * b = new(String, "b");

    // hash
    void * hash = new(Hash);
    Hash_set(hash, &a, b);
    void * c = Hash_get(hash, &a);
    puts(Object_inspect(c));
    delete(hash);

    // array
    void * ary = new(Array);
    Array_push(ary, &a);
    Array_unshift(ary, b);
    void * d = Array_shift(ary);
    puts(Object_inspect(d));
    delete(ary);

    delete(b);

    // file
    void * file = new(File, "libooc/example");
    void * content = File_read(file);
    puts(Object_inspect(content));
    delete(file);

    void write_file(void * file) {
        File_puts(file, "hello");
        File_printf(file, " w%drld", 0);
    }