Esempio n. 1
0
int test_rename(const tchar* from, const tchar* to) {
    TM_ASSERT(from);
    TM_ASSERT(to);

    internal_errno = 0;

    if (mock.rename_should_fail_with != 0) {
        internal_errno = mock.rename_should_fail_with;
        mock.rename_should_fail_with = 0;
        return -1;
    }

    auto from_index = mock.find(from);
    if (from_index < 0) {
        internal_errno = ENOENT;
        return -1;
    }

    auto to_index = mock.find(to);
    if (to_index >= 0) {
        internal_errno = EACCES;
        return -1;
    }

    mock.entries[from_index].path.assign(to, to + test_strlen(to));
    return 0;
}
Esempio n. 2
0
int			main(void)
{
	set(MAGENTA);
	set(BOLD);
	printf("\n\t\t\t\t\t\t\t\t=============== FUNCTIONS ===============\n\n");
	set(UNCOLOR);
	test_bzero();
	test_strcat();
	test_isalpha();
	test_isdigit();
	test_isalnum();
	test_isascii();
	test_isprint();
	test_toupper();
	test_tolower();
	test_puts();
	test_strlen();
	test_memset();
	test_memcpy();
	test_strdup();

	set(MAGENTA);
	set(BOLD);
	printf("\t\t\t\t\t\t\t\t================= BONUS =================\n\n");
	set(UNCOLOR);
	test_islower();
	test_isupper();
	test_strcpy();
	test_putchar();
	test_putstr();
	return (0);
}
Esempio n. 3
0
File: main.c Progetto: jwalle/libASM
/*
void	test_putstr(void)
{
	char	str[] = "PUTSTR";
	printf("\033[1;33m%s\033[0m\n", str);
	ft_putstr("Bonjour");
	ft_putstr(" les");
	ft_putstr(" amis");
	ft_putstr(" !");
	ft_putstr("\n");
	ft_putstr(NULL);
	ft_putstr("\n");
	printf("\033[1;32m%s passed.\033[0m\n\n", str);
}

void	test_add(void)
{
//This function adds i & j
	char	str[] = "ADD";

	printf("\033[1;33m%s\033[0m\n", str);
	printf("3 + 5 = %d\n", ft_add(3, 5));
	printf("39 + 39 = %d\n", ft_add(39, 39));
	printf("0 + 0 = %d\n", ft_add(0, 0));
	printf("0 + (-100) = %d\n", ft_add(0, -100));
	printf("\033[1;32m%s passed.\033[0m\n\n", str);
}

void	test_mult(void)
{
//This function multiplies i & j
	char	str[] = "MULT";

	printf("\033[1;33m%s\033[0m\n", str);
	printf("3 * 5 = %d\n", ft_mult(3, 5));
	printf("39 * 39 = %d\n", ft_mult(39, 39));
	printf("-3 * -1000 = %d\n", ft_mult(-3, -1000));
	printf("0 * (-100) = %d\n", ft_mult(0, -100));
	printf("\033[1;32m%s passed.\033[0m\n\n", str);
}

void	test_putstr_fd(void)
{
	char	str[] = "PUTSTR_FD";
	printf("\033[1;33m%s\033[0m\n", str);
	ft_putstr_fd("Bonjour", 2);
	ft_putstr_fd(" les", 1);
	ft_putstr_fd(" amis", 2);
	ft_putstr_fd(" !", 1);
	ft_putstr_fd("\n", 3);
	ft_putstr_fd(NULL, 1);
	ft_putstr_fd("\n", 1);
	printf("\033[1;32m%s passed.\033[0m\n\n", str);
}

void	test_strclr(void)
{
	char	str[] = "STRCLR";
	char	str1[] = "COUCOU";
	char	str2[] = "LES";
	printf("\033[1;33m%s\033[0m\n", str);
	
	printf("%s et %s deviennent :  \n", str1, str2);
	ft_strclr(str1);
	ft_strclr(str2);
	printf("%s et %s\n", str1, str2);
	printf("\033[1;32m%s passed.\033[0m\n\n", str);
}
*/
int		main(void)
{
	test_isascii();
	test_isdigit();
	test_isalpha();
	test_isalnum();
	test_isprint();
	test_bzero();
	//test_toupper();
	//test_tolower();
	test_strlen();
	test_strcat();
	test_memset();
	test_memcpy();
	test_puts();
	test_strdup();
	test_cat();
	printf("\n\n\033[1;32m  !!  BONUS  !!  \033[0m\n\n");
	//test_putstr();
	//test_add();
	//test_mult();
	//test_putstr_fd();
	//test_strclr();
	test_strnew();
	test_putchar();
	return (0);
}
Esempio n. 4
0
int main(int argc, char **argv)
{
	test_strlen();

	test_strcat();
	return 0;
}
Esempio n. 5
0
int main()
{
	//strcpy
	printf("%d\n", test_strcpy("hello", 0));

	//strncpy
	printf("%d\n", test_strncpy("hellohellohello", 7, 0));
	printf("%d\n", test_strncpy("hello", 7, 0));
	printf("%d\n", test_strncpy("hellohello", 10, 0));

	//strcmp
	printf("%d\n", test_strcmp("aaa", "arc", 0));
	printf("%d\n", test_strcmp("abc", "abc", 0));
	printf("%d\n", test_strcmp("ccc", "abc", 0));

	//strncmp
	printf("%d\n", test_strncmp("aaaddd", "alcccc", 3, 0));
	printf("%d\n", test_strncmp("abcddd", "abcccc", 3, 0));
	printf("%d\n", test_strncmp("cccddd", "abcccc", 3, 0));

	//strcat
	printf("%d\n", test_strcat("world", "hello", 0));
	printf("%d\n", test_strcat("fg", "", 0));
	printf("%d\n", test_strcat("", "hello", 0));

	//strncat
	printf("%d\n", test_strncat("world", "hello", 3, 0));
	printf("%d\n", test_strncat("world", "hello", 10, 0));
	printf("%d\n", test_strncat("", "hello", 10, 0));

	//strlen
	printf("%d\n", test_strlen("", 0));
	printf("%d\n", test_strlen("hello", 0));

	//strchr
	printf("%d\n", test_strchr("world", 'r', 0));
	printf("%d\n", test_strchr("world", 'a', 0));
	printf("%d\n", test_strchr("", 'a', 0));

	//strstr
	printf("%d\n", test_strstr("world", "rl", 0));
	printf("%d\n", test_strstr("needle", "nee", 0));
	printf("%d\n", test_strstr("world", "hello", 0));


	return 0;
}
Esempio n. 6
0
open_file* test_fopen(const tchar* filename, const tchar* mode) {
    TM_ASSERT(filename);
    TM_ASSERT(mode);

    TM_ASSERT(!mock.file.is_open);
    TM_ASSERT(!mock.file.is_writable);

    internal_errno = 0;

    if (mock.fopen_should_fail_with) {
        internal_errno = mock.fopen_should_fail_with;
        mock.fopen_should_fail_with = 0;
        return nullptr;
    }

    bool is_writable = false;

    if (*mode == 'r') {
        ++mode;
    } else if (*mode == 'w') {
        ++mode;
        is_writable = true;
    }

    if (*mode == 'b') ++mode;

    auto index = mock.find_file(filename);

    if (is_writable) {
    	if (index < 0) {
    		mock.entries.push_back({});
    		auto& added = mock.entries.back();
    		added.path.assign(filename, filename + test_strlen(filename));
    		added.type = mock_file;
    		index = (int32_t)(mock.entries.size() - 1);
    	}
    }

	if (index < 0) {
	    internal_errno = ENOENT;
	    return nullptr;
	}

    const auto& entry = mock.entries[index];
    mock.file = {};
    mock.file.is_open = true;
    mock.file.is_writable = is_writable;
    mock.file.read_contents = nullptr;
    mock.file.file_io_entry_index = index;
    mock.file.read_contents_size = 0;
    if (!entry.contents.empty()) {
	    mock.file.read_contents_size = entry.contents.size();
    	mock.file.read_contents = entry.contents.data();
    }
    return &mock.file;
}
Esempio n. 7
0
 int32_t find_file(const tchar* path) const {
 	auto path_len = test_strlen(path);
     for (int32_t i = 0, count = (int32_t)entries.size(); i < count; ++i) {
         const auto& entry = entries[i];
         if (entry.type == mock_file && equal_file(entry.path, path, path_len)) {
             return i;
         }
     }
     return -1;
 }
Esempio n. 8
0
size_t get_parent_path_size(const tchar* first) {
	TM_ASSERT(first);

	if (!*first || !*(first + 1)) return 0;

	auto last = first + test_strlen(first) - 1;
	if (*last == path_delim) --last;

	while (first != last) {
		if (*last == path_delim) return (size_t)(last - first);
		--last;
	}
	return 0;
}
Esempio n. 9
0
int main(int argc, char** argv){
#ifdef USE_SECURE_LIB
	printf("USE secure lib\n");
#else
	printf("NOT USE secure lib\n");
#endif
	test_strncpy();
	test_strncat();
	test_strlen();
	test_snprintf();
	test_popen();
	test_usleep();
	return 0;
}
Esempio n. 10
0
int main()
{
	test_strchr();
	test_strcmp();
	test_strncmp();
	test_strcpy();
	test_strncpy();
	test_strcspn();
	test_strlen();
	test_strcat();
	test_strncat();
	test_strpbrk();
	test_strrchr();
	test_strspn();
	test_strstr();
	test_strtok();
	return 0;
}
Esempio n. 11
0
File: main.c Progetto: AzizArouss/42
int		main(void)
{
	ft_puts("\033[33m\n/!\\Change test_is last value from '0' to '1'\ndirectly in main if you want to see tests details./!\\\n\033[00m");
	test_is(isdigit, ft_isdigit, "isdigit", 0);
	test_is(isalnum, ft_isalnum, "isalnum", 0);
	test_is(isalpha, ft_isalpha, "isalpha", 0);
	test_is(isascii, ft_isascii, "isascii", 0);
	test_is(toupper, ft_toupper, "toupper", 0);
	test_is(tolower, ft_tolower, "tolower", 0);
	test_bzero(ft_bzero, "bzero", 10);
	test_strcat(ft_strcat, "strcat");
	test_puts(ft_puts, "ft_puts");
	test_strlen(ft_strlen, "strlen", 26);
	test_memset(ft_memset, "memset", 10);
	test_memcpy("memcpy", 26);
	test_strdup("strdup", 10);
	ft_puts("");
	return (0);
}
Esempio n. 12
0
File: main.c Progetto: ptitmax/42
int main()
{
	test_isalpha();
	test_isdigit();
	test_isalnum();
	test_isascii();
	test_isprint();
	test_tolower();
	test_toupper();
	test_bzero();
	test_strcat();
	test_strlen();
	test_memset();
	test_memcpy();
	test_puts();
	test_strdup();
	test_strcmp();
	test_cat();
	test_isspace();
}
Esempio n. 13
0
int main(int argc, char **argv)
{
  test_memcpy();
  test_memmove();
  test_strlen();
  test_strnlen();
  test_memset();
  test_strcmp();
  test_strncmp();
  test_memcmp();
  test_strcat();
  // strncat is not tested (code from the man page)
  test_strcpy();
  test_strncpy();
  test_strchr();
  test_strrchr();
  test_memchr();
  test_memrchr();
  test_strstr();
  // strerror not tested
  // strdup not tested (uses malloc)
  // strndup not tested (uses malloc)
  return 0;
}
Esempio n. 14
0
int test_mkdir(const tchar* path) {
    TM_ASSERT(path);

    internal_errno = 0;
    if (mock.mkdir_should_fail_with != 0) {
        internal_errno = mock.mkdir_should_fail_with;
        mock.mkdir_should_fail_with = 0;
        return -1;
    }

    if (!*path) {
        internal_errno = ENOENT;
        return -1;
    }

    if (mock.find_dir(path) >= 0) {
        internal_errno = EEXIST;
        return -1;
    }
    if (mock.find_file(path) >= 0) {
        internal_errno = ENOTDIR;
        return -1;
    }

    auto parent_size = get_parent_path_size(path);
    if (parent_size > 0 && mock.find_dir(path, parent_size) < 0) {
    	internal_errno = ENOENT;
    	return -1;
    }

    mock.entries.push_back({});
    auto& entry = mock.entries.back();
    entry.path.assign(path, path + test_strlen(path));
    entry.type = mock_dir;
    return 0;
}
Esempio n. 15
0
int main(int argc, char* argv[])
{
	int  ch, n = 1, conn_timeout = 10, rw_timeout = 10, ttl = 10;
	acl::string addr("127.0.0.1:6379"), cmd;

	while ((ch = getopt(argc, argv, "hs:n:C:I:a:t:")) > 0)
	{
		switch (ch)
		{
		case 'h':
			usage(argv[0]);
			return 0;
		case 's':
			addr = optarg;
			break;
		case 'n':
			n = atoi(optarg);
			break;
		case 'C':
			conn_timeout = atoi(optarg);
			break;
		case 'I':
			rw_timeout = atoi(optarg);
			break;
		case 'a':
			cmd = optarg;
			break;
		case 't':
			ttl = atoi(optarg);
			break;
		default:
			break;
		}
	}

	acl::acl_cpp_init();
	acl::log::stdout_open(true);
	acl::redis_client client(addr.c_str(), conn_timeout, rw_timeout);
	acl::redis_string option(&client);

	bool ret;

	if (cmd == "set")
		ret = test_set(option, n);
	else if (cmd == "setex")
		ret = test_setex(option, n, ttl);
	else if (cmd == "setnx")
		ret = test_setnx(option, n);
	else if (cmd == "append")
		ret = test_append(option, n);
	else if (cmd == "get")
		ret = test_get(option, n);
	else if (cmd == "getset")
		ret = test_getset(option, n);
	else if (cmd == "strlen")
		ret = test_strlen(option, n);
	else if (cmd == "mset")
		ret = test_mset(option, n);
	else if (cmd == "mget")
		ret = test_mget(option, n);
	else if (cmd == "msetnx")
		ret = test_msetnx(option, n);
	else if (cmd == "setrange")
		ret = test_setrange(option, n);
	else if (cmd == "getrange")
		ret = test_getrange(option, n);
	else if (cmd == "setbit")
		ret = test_setbit(option, n);
	else if (cmd == "getbit")
		ret = test_getbit(option, n);
	else if (cmd == "bitcount")
		ret = test_bitcount(option, n);
	else if (cmd == "bitop_and")
		ret = test_bitop_and(option, n);
	else if (cmd == "bitop_or")
		ret = test_bitop_or(option, n);
	else if (cmd == "bitop_xor")
		ret = test_bitop_xor(option, n);
	else if (cmd == "incr")
		ret = test_incr(option, n);
	else if (cmd == "incrby")
		ret = test_incrby(option, n);
	else if (cmd == "incrbyfloat")
		ret = test_incrbyfloat(option, n);
	else if (cmd == "decr")
		ret = test_decr(option, n);
	else if (cmd == "decrby")
		ret = test_decrby(option, n);
	else if (cmd == "all")
	{
		ret = test_set(option, n)
			&& test_setex(option, n, ttl)
			&& test_setnx(option, n)
			&& test_append(option, n)
			&& test_get(option, n)
			&& test_getset(option, n)
			&& test_strlen(option, n)
			&& test_mset(option, n)
			&& test_mget(option, n)
			&& test_msetnx(option, n)
			&& test_setrange(option, n)
			&& test_getrange(option, n)
			&& test_setbit(option, n)
			&& test_getbit(option, n)
			&& test_bitcount(option, n)
			&& test_bitop_and(option, n)
			&& test_bitop_or(option, n)
			&& test_bitop_xor(option, n)
			&& test_incr(option, n)
			&& test_incrby(option, n)
			&& test_incrbyfloat(option, n)
			&& test_decr(option, n)
			&& test_decrby(option, n);
	}
	else
	{
		ret = false;
		printf("unknown cmd: %s\r\n", cmd.c_str());
	}

	if (ret == true)
		printf("test OK!\r\n");
	else
		printf("test failed!\r\n");

#ifdef WIN32
	printf("enter any key to exit\r\n");
	getchar();
#endif
	return 0;
}
Esempio n. 16
0
int		main(void)
{
	printf("\n");

	printf ("\033[31m1 = Oui / 0 = Non\n\n\033[0m");
	
	printf("\033[33m=== FT_BZERO   ===\n\033[0m");

		test_bzero();
		printf("\n");
	
	printf("\033[33m=== FT_STRCAT  ===\n\033[0m");	
	
		test_strcat();
		printf("\n");

	printf("\033[33m=== FT_ISALPHA ===\n\033[0m");
	
		test_isalpha();
		printf("\n");

	printf("\033[33m=== FT_ISDIGIT ===\n\033[0m");
	
		test_isdigit();
		printf("\n");

	printf("\033[33m=== FT_ISALNUM ===\n\033[0m");
	
		test_isalnum();
		printf("\n");

	printf("\033[33m=== FT_ISASCII ===\n\033[0m");
	
		test_isascii();
		printf("\n");

	printf("\033[33m=== FT_ISPRINT ===\n\033[0m");

		test_isprint();
		printf("\n");
	printf("\033[33m=== FT_TOUPPER ===\n\033[0m");

		test_toupper();
		printf("\n");

	printf("\033[33m=== FT_TOLOWER ===\n\033[0m");

		test_tolower();
		printf("\n");

	printf("\033[33m=== FT_PUTS ===\n\033[0m");

		test_puts();
		printf("\n");

	printf("\033[33m=== FT_STRLEN ===\n\033[0m");

		test_strlen();
		printf("\n");

	printf("\033[33m=== FT_MEMSET ===\n\033[0m");	

		test_memset();
		printf("\n");

	printf("\033[33m=== FT_STRDUP ===\n\033[0m");

		test_strdup();
		printf("\n");

	printf("\033[33m=== FT_MEMCPY ===\n\033[0m");

		test_memcpy();
		printf("\n");
	
	printf("\033[33m=== FT_CAT ===\n\033[0m");

		test_cat();
		printf("\n");
	return (0);
}
Esempio n. 17
0
 int32_t find_dir(const tchar* path) const { return find_dir(path, test_strlen(path)); }