aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile11
-rw-r--r--include/libumumble.h8
-rw-r--r--src/ctx.c8
-rw-r--r--tests/Makefile19
-rw-r--r--tests/test.c11
6 files changed, 48 insertions, 10 deletions
diff --git a/.gitignore b/.gitignore
index a6fe2e2..76adb92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
build/
+tests/build/
*.a
*.so
*.pb.c
diff --git a/Makefile b/Makefile
index ddd9aaa..b5ee9c8 100644
--- a/Makefile
+++ b/Makefile
@@ -2,12 +2,15 @@ include deps/nanopb/extra/nanopb.mk
include config.mk
SRC += $(shell find src/ -type f -name '*.c')
+SRC += $(NANOPB_DIR)/pb_encode.c
+SRC += $(NANOPB_DIR)/pb_decode.c
+SRC += $(NANOPB_DIR)/pb_common.c
PROTO = $(shell find src/ -type f -name '*.proto')
OBJ = $(PROTO:%.proto=$(BUILD_DIR)/%.pb.c.o)
OBJ += $(SRC:%=$(BUILD_DIR)/%.o)
H = include/libumumble.h
-.PHONY: all static shared clean install-static install-shared install
+.PHONY: all static shared tests clean install-static install-shared install
all: static shared
@@ -18,7 +21,7 @@ shared: $(DNAME)
$(OBJ): config.mk $(PROTO)
$(SNAME): $(OBJ)
- ar -rcs $@ $^
+ ar rcs $@ $?
$(DNAME): LDFLAGS += -shared
$(DNAME): $(OBJ)
@@ -28,8 +31,12 @@ $(BUILD_DIR)/%.c.o: %.c
mkdir -p '$(@D)'
$(CC) -c -o $@ $(INCLUDES) $(CFLAGS) $<
+tests:
+ $(MAKE) -C tests
+
clean:
rm -rf $(SNAME) $(DNAME) $(BUILD_DIR) src/*.pb.h src/*.pb.c
+ $(MAKE) -C tests clean
install-header:
install -m 644 $(H)
diff --git a/include/libumumble.h b/include/libumumble.h
index 2605688..3a66099 100644
--- a/include/libumumble.h
+++ b/include/libumumble.h
@@ -15,17 +15,17 @@ typedef struct mumble_ctx {
* This function will allocate initial memory needed for storing e.g. the channel layout.
* Make sure to call mumble_free_ctx() when you're done!
*
- * \param ctx the context object to initialize.
+ * \param ctx pointer to the context object to initialize.
* \return int indicating success
* \retval 1 error
*/
-int mumble_init_ctx(mumble_ctx_t ctx);
+int mumble_init_ctx(mumble_ctx_t *ctx);
/* Free a mumble context.
*
- * \param ctx the context object to free.
+ * \param ctx pointer to the context object to free.
*/
-void mumble_free_ctx(mumble_ctx_t ctx);
+void mumble_free_ctx(mumble_ctx_t *ctx);
#ifdef __cplusplus
}
diff --git a/src/ctx.c b/src/ctx.c
index efa9101..0d7651a 100644
--- a/src/ctx.c
+++ b/src/ctx.c
@@ -1,15 +1,15 @@
#include <libumumble.h>
#include <uv.h>
-int mumble_init_ctx(mumble_ctx_t ctx)
+int mumble_init_ctx(mumble_ctx_t *ctx)
{
int result;
- result = uv_loop_init(&ctx.uv_loop);
+ result = uv_loop_init(&ctx->uv_loop);
return result;
}
-void mumble_free_ctx(mumble_ctx_t ctx)
+void mumble_free_ctx(mumble_ctx_t *ctx)
{
- uv_loop_close(&ctx.uv_loop);
+ uv_loop_close(&ctx->uv_loop);
}
diff --git a/tests/Makefile b/tests/Makefile
new file mode 100644
index 0000000..bc757bf
--- /dev/null
+++ b/tests/Makefile
@@ -0,0 +1,19 @@
+include ../config.mk
+INCLUDES = -I../include
+
+SRC = $(shell find -type f -name '*.c')
+BIN = $(SRC:%.c=%)
+
+LDLIBS = -luv -l:libumumble.a
+LDFLAGS = -L..
+
+.PHONY: all
+
+all: $(BIN)
+
+$(BIN): $(SRC)
+ mkdir -p '$(BUILD_DIR)'
+ $(CC) -o $(BUILD_DIR)/$@ $(CFLAGS) $(INCLUDES) $(@:%=%.c) $(LDFLAGS) $(LDLIBS)
+
+clean:
+ rm -rf $(BUILD_DIR)
diff --git a/tests/test.c b/tests/test.c
new file mode 100644
index 0000000..d96167c
--- /dev/null
+++ b/tests/test.c
@@ -0,0 +1,11 @@
+#include <libumumble.h>
+
+int main(int argc, char *argv[])
+{
+ mumble_ctx_t ctx;
+ printf("%ld\n", ctx.uv_loop.time);
+ mumble_init_ctx(&ctx);
+ printf("%ld\n", ctx.uv_loop.time);
+ mumble_free_ctx(&ctx);
+ printf("%ld\n", ctx.uv_loop.time);
+}