Пример #1
0
END_TEST

/* --------------------------------------------------------------------------------------------- */

START_TEST (test_vfs_parse_ls_lga_reorder)
{
    size_t filepos = 0;
    struct vfs_s_entry *ent1, *ent2, *ent3;
    int i;

    vfs_parse_ls_lga_init();

    ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    i = ent1->ino->st.st_nlink;
    if (! vfs_parse_ls_lga ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09      build_root1",
    &ent1->ino->st, &ent1->name, &ent1->ino->linkname, &filepos))
    {
        fail ("An error occured while parse ls output");
        return;
    }
    vfs_s_store_filename_leading_spaces (ent1, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1);


    ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    i = ent2->ino->st.st_nlink;
    if (! vfs_parse_ls_lga ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09    build_root2",
    &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos))
    {
        fail ("An error occured while parse ls output");
        return;
    }
    vfs_s_store_filename_leading_spaces (ent2, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2);

    ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    i = ent3->ino->st.st_nlink;
    if (! vfs_parse_ls_lga ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09 ..",
    &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos))
    {
        fail ("An error occured while parse ls output");
        return;
    }
    vfs_s_store_filename_leading_spaces (ent3, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3);

    vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());

    fail_unless(strcmp(ent1->name, "     build_root1") == 0, "\nactual '%s'\nnot equal to '%s'\n", ent1->name, "     build_root1");
    fail_unless(strcmp(ent2->name, "   build_root2") == 0, "\nactual '%s'\nnot equal to '%s'\n", ent2->name, "   build_root2");
}
Пример #2
0
/* *INDENT-OFF* */
END_PARAMETRIZED_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */

/* @Test */
/* *INDENT-OFF* */
START_TEST (test_vfs_parse_ls_lga_reorder)
/* *INDENT-ON* */
{
    /* given */
    size_t filepos = 0;
    struct vfs_s_entry *ent1, *ent2, *ent3;

    vfs_parse_ls_lga_init ();

    /* init ent1 */
    ent1 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    vfs_parse_ls_lga
        ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09      build_root1", &ent1->ino->st,
         &ent1->name, &ent1->ino->linkname, &filepos);
    vfs_s_store_filename_leading_spaces (ent1, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent1);


    /* init ent2 */
    ent2 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    vfs_parse_ls_lga ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09    build_root2",
                      &ent2->ino->st, &ent2->name, &ent2->ino->linkname, &filepos);
    vfs_s_store_filename_leading_spaces (ent2, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent2);

    /* init ent3 */
    ent3 = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);
    vfs_parse_ls_lga ("drwxrwxr-x   10 500      500          4096 Jun 23 17:09 ..",
                      &ent3->ino->st, &ent3->name, &ent3->ino->linkname, &filepos);
    vfs_s_store_filename_leading_spaces (ent3, filepos);
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent3);

    /* when */
    vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());

    /* then */
    mctest_assert_str_eq (ent1->name, "     build_root1");
    mctest_assert_str_eq (ent2->name, "   build_root2");
}
Пример #3
0
/* *INDENT-OFF* */
START_PARAMETRIZED_TEST (test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds)
/* *INDENT-ON* */

{
    /* given */
    size_t filepos = 0;
    struct stat etalon_stat;
    static struct stat test_stat;
    char *filename = NULL;
    char *linkname = NULL;
    gboolean actual_result;

    vfs_parse_ls_lga_init ();

    etalon_stat.st_blocks = 0;
    etalon_stat.st_size = 0;
    etalon_stat.st_mode = 0;
    fill_stat_struct (&etalon_stat, _i);

    /* when */
    actual_result =
        vfs_parse_ls_lga (data->input_string, &test_stat, &filename, &linkname, &filepos);

    /* then */
    mctest_assert_int_eq (actual_result, data->expected_result);

    mctest_assert_str_eq (filename, data->expected_filename);
    mctest_assert_str_eq (linkname, data->expected_linkname);

    mctest_assert_int_eq (etalon_stat.st_dev, test_stat.st_dev);
    mctest_assert_int_eq (etalon_stat.st_ino, test_stat.st_ino);
    mctest_assert_int_eq (etalon_stat.st_mode, test_stat.st_mode);
    mctest_assert_int_eq (etalon_stat.st_uid, test_stat.st_uid);
    mctest_assert_int_eq (etalon_stat.st_gid, test_stat.st_gid);
    mctest_assert_int_eq (etalon_stat.st_rdev, test_stat.st_rdev);
    mctest_assert_int_eq (etalon_stat.st_size, test_stat.st_size);
    mctest_assert_int_eq (etalon_stat.st_blksize, test_stat.st_blksize);
    mctest_assert_int_eq (etalon_stat.st_blocks, test_stat.st_blocks);

    /* FIXME: these commented checks are related to time zone!
       mctest_assert_int_eq (etalon_stat.st_atime, test_stat.st_atime);
       mctest_assert_int_eq (etalon_stat.st_mtime, test_stat.st_mtime);
       mctest_assert_int_eq (etalon_stat.st_ctime, test_stat.st_ctime);
     */
}
Пример #4
0
/* *INDENT-OFF* */
END_TEST
/* *INDENT-ON* */

/* --------------------------------------------------------------------------------------------- */
#define parce_one_line(ent_index, ls_output) {\
    ent[ent_index] = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);\
    if (! vfs_parse_ls_lga (ls_output,\
    &ent[ent_index]->ino->st, &ent[ent_index]->name, &ent[ent_index]->ino->linkname, &filepos))\
    {\
        fail ("An error occurred while parse ls output");\
        return;\
    }\
    vfs_s_store_filename_leading_spaces (ent[ent_index], filepos);\
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent[ent_index]);\
    \
}

/* @Test */
/* *INDENT-OFF* */
START_TEST (test_vfs_parse_ls_lga_unaligned)
/* *INDENT-ON* */
{
    /* given */
    size_t filepos = 0;
    struct vfs_s_entry *ent[4];

    vfs_parse_ls_lga_init ();

    parce_one_line (0, "drwxrwxr-x   10 500      500          4096 Jun 23 17:09  build_root1");
    parce_one_line (1, "drwxrwxr-x   10 500     500         4096 Jun 23 17:09     build_root2");
    parce_one_line (2, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09  ..");
    parce_one_line (3,
                    "drwxrwxr-x      10   500        500             4096   Jun   23   17:09   build_root 0");

    /* when */
    vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());

    /* then */
    mctest_assert_str_eq (ent[0]->name, "build_root1");
    mctest_assert_str_eq (ent[0]->name, "build_root1");
    mctest_assert_str_eq (ent[1]->name, "   build_root2");
    mctest_assert_str_eq (ent[3]->name, " build_root 0");
}
Пример #5
0
END_TEST

/* --------------------------------------------------------------------------------------------- */
#define parce_one_line(ent_index, ls_output) {\
    ent[ent_index] = vfs_s_generate_entry (&vfs_test_ops1, NULL, vfs_root_inode, 0);\
    if (! vfs_parse_ls_lga (ls_output,\
    &ent[ent_index]->ino->st, &ent[ent_index]->name, &ent[ent_index]->ino->linkname, &filepos))\
    {\
        fail ("An error occured while parse ls output");\
        return;\
    }\
    vfs_s_store_filename_leading_spaces (ent[ent_index], filepos);\
    vfs_s_insert_entry (&vfs_test_ops1, vfs_root_inode, ent[ent_index]);\
    \
}
#define fail_unless_ent(ent_index, etalon_str){\
    fail_unless(\
        strcmp(ent[ent_index]->name, etalon_str) == 0,\
        "\nactual '%s'\nnot equal to '%s'\n", ent[ent_index]->name, etalon_str\
    );\
}

START_TEST (test_vfs_parse_ls_lga_unaligned)
{
    size_t filepos = 0;
    struct vfs_s_entry *ent[4];

    vfs_parse_ls_lga_init();

    parce_one_line(0, "drwxrwxr-x   10 500      500          4096 Jun 23 17:09  build_root1");
    parce_one_line(1, "drwxrwxr-x   10 500     500         4096 Jun 23 17:09     build_root2");
    parce_one_line(2, "drwxrwxr-x 10 500 500 4096 Jun 23 17:09  ..");
    parce_one_line(3, "drwxrwxr-x      10   500        500             4096   Jun   23   17:09   build_root 0");

    vfs_s_normalize_filename_leading_spaces (vfs_root_inode, vfs_parse_ls_lga_get_final_spaces ());

    fail_unless_ent(0, "build_root1");
    fail_unless_ent(1, "   build_root2");
    fail_unless_ent(3, " build_root 0");

}