# define STDERR_FILENO 2
#endif
+#define INV_FD -3
+
/****************************************************************************
* Global Variables
****************************************************************************/
struct stat st;
int fd1, fd2, ret;
off_t size;
+ off_t offset;
snprintf(dest_file, sizeof(dest_file), "%s_dest", src_file);
TC_ASSERT_EQ_CLEANUP("stat", ret, OK, close(fd1));
size = st.st_size;
+ /* case-1: offset = 0 */
fd2 = open(dest_file, O_WRONLY | O_CREAT);
TC_ASSERT_GEQ_CLEANUP("open", fd2, 0, close(fd1));
ret = sendfile(fd2, fd1, 0, size);
- close(fd1);
close(fd2);
- TC_ASSERT_EQ("sendfile", ret, size);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, size, close(fd1));
ret = stat(dest_file, &st);
+ TC_ASSERT_EQ_CLEANUP("stat", ret, OK, close(fd1));
+ TC_ASSERT_EQ_CLEANUP("stat", st.st_size, size, close(fd1));
+
+ /* case-2: offset = 1 */
+ fd2 = open(dest_file, O_WRONLY | O_CREAT);
+ TC_ASSERT_GEQ_CLEANUP("open", fd2, 0, close(fd1));
+
+ offset = 1;
+ ret = sendfile(fd2, fd1, &offset, size - 1);
+ close(fd2);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, size - 1, close(fd1));
+
+ ret = stat(dest_file, &st);
+ TC_ASSERT_EQ_CLEANUP("stat", ret, OK, close(fd1));
+ TC_ASSERT_EQ_CLEANUP("stat", st.st_size, size - 1, close(fd1));
+
+ /* case-3: offset = 1, invalid input fd, returns ERROR */
+ fd2 = open(dest_file, O_WRONLY | O_CREAT);
+ TC_ASSERT_GEQ_CLEANUP("open", fd2, 0, close(fd1));
+
+ offset = 1;
+ ret = sendfile(fd2, INV_FD, &offset, size - 1);
+ close(fd2);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, ERROR, close(fd1));
+
+ /* case-4: invalid input fd, returns ERROR */
+ fd2 = open(dest_file, O_WRONLY | O_CREAT);
+ TC_ASSERT_GEQ_CLEANUP("open", fd2, 0, close(fd1));
+
+ ret = sendfile(fd2, INV_FD, NULL, size);
+ close(fd2);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, ERROR, close(fd1));
+
+ /* case-5: offset = 0, invalid output fd, returns ERROR */
+ offset = 0;
+ ret = sendfile(INV_FD, fd1, &offset, size);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, ERROR, close(fd1));
+
+ /* case-6: current offset of input file is EOF, returns ERROR */
+ fd2 = open(dest_file, O_WRONLY | O_CREAT);
+ TC_ASSERT_GEQ_CLEANUP("open", fd2, 0, close(fd1));
+
+ ret = lseek(fd1, 0, SEEK_END);
+ TC_ASSERT_EQ_CLEANUP("lseek", ret, size, close(fd1);close(fd2));
+
+ ret = sendfile(fd2, fd1, NULL, size);
+ close(fd2);
+ TC_ASSERT_EQ_CLEANUP("sendfile", ret, 0, close(fd1));
+
+ ret = stat(dest_file, &st);
+ close(fd1);
TC_ASSERT_EQ("stat", ret, OK);
- TC_ASSERT_EQ("stat", size, st.st_size);
+ TC_ASSERT_EQ("stat", st.st_size, 0);
+
TC_SUCCESS_RESULT();
}
#include <tinyara/config.h>
#include <stdio.h>
#include <string.h>
+#include <tinyara/regex.h>
#include <unistd.h>
#include <errno.h>
#include <libgen.h>
#include <crc32.h>
#include "tc_internal.h"
+#define BUFF_SIZE 256
#define USEC_100 100
#define VAL_50 50
#define VAL_71 71
TC_SUCCESS_RESULT();
}
+/**
+ * @fn :tc_libc_misc_lib_dumpbuffer
+ * @brief :Do a pretty buffer dump
+ * @scenario :Do a pretty buffer dump
+ * @API's covered :lib_dumpbuffer
+ * @Preconditions :None
+ * @Postconditions :None
+ * @Return :void
+ */
+static void tc_libc_misc_lib_dumpbuffer(void)
+{
+ const char *msg = "tc_libc_misc_lib_dumpbuffer";
+ unsigned char buffer[] = { 'S', 'A', 'M', 'S', 'U', 'N', 'G', '-', 'T', 'i', 'z', 'e', 'n', 'R', 'T' };
+ unsigned char *buf = NULL;
+ int idx;
+
+ /**
+ * As lib_dumpbuffer returns void, there in no way to check the success or failure case
+ * we need to manually check the dump output
+ * Case-1: output: 53414d53554e472d54697a656e5254 SAMSUNG-TizenRT
+ * Case-2: output: 0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a ............... (i.e, 256 "0a")
+ */
+
+ /* Case-1 */
+ lib_dumpbuffer(msg, buffer, sizeof(buffer));
+
+ /* Case-2 */
+ buf = (unsigned char *)malloc(BUFF_SIZE);
+ TC_ASSERT_NEQ("malloc", buf, NULL);
+
+ for (idx = 0; idx < BUFF_SIZE; idx++) {
+ buf[idx] = 0xA;
+ }
+ lib_dumpbuffer(msg, buf, BUFF_SIZE);
+
+ free(buf);
+ buf = NULL;
+
+ TC_SUCCESS_RESULT();
+}
+
+/**
+ * @fn :tc_libc_misc_match
+ * @brief :Simple shell-style filename pattern matcher
+ * @scenario :Returns 1 (match) or 0 (no-match)
+ * @API's covered :match
+ * @Preconditions :None
+ * @Postconditions :None
+ * @Return :void
+ */
+static void tc_libc_misc_match(void)
+{
+ const char *pattern = "?|";
+ const char *string = "S";
+ int ret;
+
+ ret = match(pattern, string);
+ TC_ASSERT_EQ("match", ret, 1);
+
+ pattern = "somepattern";
+ string = "nomatch";
+ ret = match(pattern, string);
+ TC_ASSERT_EQ("match", ret, 0);
+
+ TC_SUCCESS_RESULT();
+}
+
/****************************************************************************
* Name: libc_misc
****************************************************************************/
#ifdef CONFIG_DEBUG
#ifdef CONFIG_DEBUG_ERROR
tc_libc_misc_dbg();
+ tc_libc_misc_lib_dumpbuffer();
#ifdef CONFIG_ARCH_LOWPUTC
tc_libc_misc_lldbg();
#endif
#endif
#endif
#endif /* CONFIG_DEBUG */
+ tc_libc_misc_match();
return 0;
}