Commit 1ff0b996 authored by NzSN's avatar NzSN

Proto tests

parent 4a87c819
......@@ -32,6 +32,7 @@ install(TARGETS ffmpegprotos
if(DEBUG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
set(LIBAV libav)
ExternalProject_Add(
libav
......@@ -62,8 +63,8 @@ add_custom_command(TARGET unittest PRE_BUILD
${CMAKE_SOURCE_DIR}/resources/ $<TARGET_FILE_DIR:unittest>/resources)
add_test(
NAME UNITTEST_DIRECTLY
COMMAND valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-fil=valgrind-log.txt ./unittest)
NAME unittest
COMMAND valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=log.txt ./unittest)
# Link Google Test
target_link_libraries(unittest
......
......@@ -8,10 +8,18 @@ Proto* createProto(ReadFunc rf, WriteFunc wf, SeekFunc sf, void *priv) {
p->seek = sf;
p->priv = priv;
p->avioBuffer = NULL;
p->ctx = NULL;
return p;
}
void destroyProto(Proto **p) {
Proto *p_ = *p;
avio_context_free(&p_->ctx);
free(p_);
*p = NULL;
}
Proto createProto_(ReadFunc rf, WriteFunc wf, SeekFunc sf, void *priv) {
Proto p = {
......@@ -35,5 +43,7 @@ AVIOContext* proto2AVIO(Proto *p, size_t bufSize) {
p->write,
p->seek);
p->ctx = ioctx;
return ioctx;
}
......@@ -14,6 +14,7 @@ typedef struct Proto {
int64_t (*seek)(void *opaque, int64_t offset, int whence);
void *priv;
unsigned char *avioBuffer;
AVIOContext *ctx;
} Proto;
/* Member function implement as macros */
......@@ -26,6 +27,7 @@ typedef struct Proto {
/* Prototypes */
Proto* createProto(ReadFunc rf, WriteFunc wr, SeekFunc sf, void *priv);
void destroyProto(Proto**);
Proto createProto_(ReadFunc rf, WriteFunc wr, SeekFunc sf, void *priv);
AVIOContext* proto2AVIO(Proto *p, size_t bufSize);
......
#include "ctest.h"
#include "proto.h"
#include <math.h>
#include "basic/utils.h"
#include "basic/container/list.h"
......@@ -54,6 +55,11 @@ CTEST_SETUP(PROTO_TEST) {
data->proto = createProto(readFake, writeFake, seekFake, data->datas);
}
CTEST_TEARDOWN(PROTO_TEST) {
destroyList(&data->datas);
destroyProto(&data->proto);
}
CTEST2(PROTO_TEST, READ_WRITE) {
uint8_t *rBuf, *wBuf;
......@@ -63,17 +69,20 @@ CTEST2(PROTO_TEST, READ_WRITE) {
wBuf = (uint8_t*)malloc(1024);
memset(wBuf, 0, 1024);
for (int i = 0; i < 256; i++) {
wBuf[i] = i;
for (int i = 0; i < 1000; i++) {
wBuf[i] = i % (int)exp2(8);
write(data->proto, wBuf, 1024);
wBuf[i] = 0;
}
for (int i = 0; i < 256; i++) {
for (int i = 0; i < 1000; i++) {
read(data->proto, rBuf, 1024);
ASSERT_EQUAL(rBuf[i], i);
ASSERT_EQUAL(rBuf[i], i % (int)exp2(8));
rBuf[i] = 0;
}
free(rBuf);
free(wBuf);
}
CTEST2(PROTO_TEST, SEEK) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment