示例#1
0
static void test_rewind(skiatest::Reporter* reporter) {
    SkSWriter32<32> writer;
    int32_t array[3] = { 1, 2, 4 };

    REPORTER_ASSERT(reporter, 0 == writer.bytesWritten());
    for (size_t i = 0; i < SK_ARRAY_COUNT(array); ++i) {
        writer.writeInt(array[i]);
    }
    check_contents(reporter, writer, array, sizeof(array));

    writer.rewindToOffset(2*sizeof(int32_t));
    REPORTER_ASSERT(reporter, sizeof(array) - 4 == writer.bytesWritten());
    writer.writeInt(3);
    REPORTER_ASSERT(reporter, sizeof(array) == writer.bytesWritten());
    array[2] = 3;
    check_contents(reporter, writer, array, sizeof(array));

    // test rewinding past allocated chunks. This used to crash because we
    // didn't truncate our link-list after freeing trailing blocks
    {
        SkWriter32 writer;
        for (int i = 0; i < 100; ++i) {
            writer.writeInt(i);
        }
        REPORTER_ASSERT(reporter, 100*4 == writer.bytesWritten());
        for (int j = 100*4; j >= 0; j -= 16) {
            writer.rewindToOffset(j);
        }
        REPORTER_ASSERT(reporter, writer.bytesWritten() < 16);
    }
}
示例#2
0
void do_alloc(struct Reap *r) {
  int i=0;
  do_free(r);
  for(i=0;i<10;i++) {
    unsigned int size = 512;//pow(2, (rand() % 10));
    if(size < 4)  size = 4;
    void *a = _reap_malloc(&r->h, CYC_CORE_UNIQUE_AQUAL, size);
    if(!a) {
      return;
    }
    memset(a, 0xff, size);
    r->counter++;
    printf("%s: alloc'd pointer %d (0x%x) of %d bytes ...", r->h.name, r->counter, a, size);
    printf("Checking initialization...");fflush(stdout);
    if(check_contents(a, size,0xff,0))
      exit(-1);
    printf("ok\n");
    struct ReapPtrs *n = (struct ReapPtrs*)malloc(sizeof(struct ReapPtrs));
    n->ptr = a;
    n->next = r->p;
    n->ix = r->counter;
    n->size = size;
    r->p = n;
  }
}
示例#3
0
static void test_string_null(skiatest::Reporter* reporter) {
    uint8_t storage[8];
    SkWriter32 writer(storage, sizeof(storage));

    // Can we write nullptr?
    writer.writeString(nullptr);
    const int32_t expected[] = { 0x0, 0x0 };
    check_contents(reporter, writer, expected, sizeof(expected));
}
示例#4
0
static void test_safe_open_extra_slashes_relative(void)
{
    setup_tempfiles();

    int fd;
    assert_true((fd = safe_open(TEST_SUBSUBDIR "//..////" TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_SUBSTRING);
    close(fd);

    return_to_test_dir();
}
示例#5
0
static void test_safe_open_currentdir(void)
{
    setup_tempfiles();

    int fd;
    assert_true((fd = safe_open(TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_STRING);
    close(fd);

    return_to_test_dir();
}
示例#6
0
void do_free(struct Reap *r) {
  struct ReapPtrs *p = r->p;
  struct ReapPtrs *first = NULL;
  struct ReapPtrs *prev = NULL;
  struct ReapPtrs *tmp = NULL;
  while(p) {
    if((rand() % 10) < 4) {
      printf("%s: freeing pointer %d (0x%x) of size %d ... ", r->h.name, p->ix, p->ptr, p->size);fflush(stdout);
      if(check_contents(p->ptr, p->size, 0xff,0)) {
	printf("corrupted memory\n");
	exit(-1);
      }
      Cyc_Core_rufree(&r->h, p->ptr);
      //      if(p->size > 8)
      //	*(((unsigned char*)p->ptr) + 8) = 0xff;
      if(check_contents(p->ptr, p->size, 0x55,8)) {
	printf("memory not poisoned\n");
	exit(-1);
      }
      printf("freed\n");
      if(prev) {
	prev->next = p->next;
	free(p);
	p = prev->next;
      }
      else {
	tmp = p->next;
	free(p);
	p = tmp;
      }
    }
    else {
      if(!first)
	first = p;
      prev = p;
      p = p->next;
    }
  }
  r->p = first;
}
示例#7
0
static void test_safe_open_upupdir(void)
{
    setup_tempfiles();

    chdir_or_exit(TEST_SUBSUBDIR);

    int fd;
    assert_true((fd = safe_open("../../" TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_STRING);
    close(fd);

    return_to_test_dir();
}
示例#8
0
static void test_safe_open_generic_absolute_dir(void)
{
    setup_tempfiles();

    int fd;
    assert_true((fd = safe_open(TEMP_DIR "/"
                                TEST_SUBDIR "/../"
                                TEST_SUBSUBDIR "/../"
                                TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_SUBSTRING);
    close(fd);

    return_to_test_dir();
}
示例#9
0
static void test_safe_open_safe_dir_symlink(void)
{
    setup_tempfiles();

    TEST_SYMLINK_COUNTDOWN = 1;
    TEST_SYMLINK_NAME = TEMP_DIR "/" TEST_LINK;
    TEST_SYMLINK_TARGET = TEST_SUBDIR;
    test_switch_symlink();

    int fd;
    assert_true((fd = safe_open(TEST_LINK "/" TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_SUBSTRING);
    close(fd);

    return_to_test_dir();
}
示例#10
0
static void test_safe_open_safe_switched_symlink(void)
{
    setup_tempfiles();

    TEST_SYMLINK_COUNTDOWN = 3;
    TEST_SYMLINK_NAME = TEMP_DIR "/" TEST_FILE;
    TEST_SYMLINK_TARGET = TEMP_DIR "/" TEST_SUBDIR "/" TEST_FILE;
    // Not calling this function will call it right in the middle of the
    // safe_open() instead.
    //test_switch_symlink();

    int fd;
    assert_true((fd = safe_open(TEMP_DIR "/" TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_SUBSTRING);
    close(fd);

    return_to_test_dir();
}
示例#11
0
static void test_safe_open_safe_switched_dir_symlink(void)
{
    setup_tempfiles();

    assert_int_equal(mkdir(TEMP_DIR "/" TEST_LINK, 0755), 0);
    if (getuid() == 0)
    {
        assert_int_equal(chown(TEMP_DIR "/" TEST_LINK, 100, 100), 0);
    }

    TEST_SYMLINK_COUNTDOWN = 1;
    TEST_SYMLINK_NAME = TEMP_DIR "/" TEST_LINK;
    TEST_SYMLINK_TARGET = TEST_SUBDIR;
    // Not calling this function will call it right in the middle of the
    // safe_open() instead.
    //test_switch_symlink();

    int fd;
    assert_true((fd = safe_open(TEST_LINK "/" TEST_FILE, O_RDONLY)) >= 0);
    check_contents(fd, TEST_SUBSTRING);
    close(fd);

    return_to_test_dir();
}
示例#12
0
static void
test_basic (void)
{
    MooEditor *editor;
    MooEdit *doc, *doc2;
    GtkTextBuffer *buffer;
    char *filename;
    MooOpenInfo *info;

    editor = moo_editor_instance ();
    filename = g_build_filename (test_data.working_dir, "test.txt", NULL);
    info = moo_open_info_new (filename, NULL, -1, 0);
    doc = moo_editor_new_file (editor, info, NULL, NULL);

    TEST_ASSERT (doc != NULL);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, "");

    buffer = moo_edit_get_buffer (doc);

    gtk_text_buffer_set_text (buffer, TT1, -1);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT1);

    gtk_text_buffer_set_text (buffer, TT2, -1);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT2);

    gtk_text_buffer_set_text (buffer, TT2 LE, -1);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT2 LE);

    gtk_text_buffer_set_text (buffer, TT3, -1);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT3);

    doc2 = moo_editor_open_path (editor, filename, NULL, -1, NULL);
    TEST_ASSERT (doc2 == doc);

    TEST_ASSERT (moo_edit_close (doc));
    TEST_ASSERT (moo_editor_get_doc (editor, filename) == NULL);

    g_file_set_contents (filename, TT4, -1, NULL);
    doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
    TEST_ASSERT (doc != NULL);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT4);
    TEST_ASSERT (moo_edit_close (doc));

    g_file_set_contents (filename, TT5, -1, NULL);
    doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
    TEST_ASSERT (doc != NULL);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT5);
    TEST_ASSERT (moo_edit_close (doc));

    g_file_set_contents (filename, TT6, -1, NULL);
    doc = moo_editor_open_path (editor, filename, NULL, -1, NULL);
    TEST_ASSERT (doc != NULL);
    TEST_ASSERT (moo_edit_save (doc, NULL));
    check_contents (filename, TT6);
    TEST_ASSERT (moo_edit_close (doc));

    g_object_unref (info);
    g_free (filename);
}