C ordening
This commit is contained in:
3
C/C3 Watch/.gitignore
vendored
Normal file
3
C/C3 Watch/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
watch
|
||||
watch_test
|
||||
|
||||
42
C/C3 Watch/Makefile
Normal file
42
C/C3 Watch/Makefile
Normal file
@@ -0,0 +1,42 @@
|
||||
PROD_DIR := ./product
|
||||
SHARED_DIR := ./shared
|
||||
TEST_DIR := ./test
|
||||
UNITY_FOLDER :=./Unity
|
||||
RES_DIR := ./ResourceDetector
|
||||
BUILD_DIR :=./build
|
||||
|
||||
PROD_EXEC = main
|
||||
PROD_DIRS := $(PROD_DIR) $(SHARED_DIR) $(RES_DIR)
|
||||
PROD_FILES := $(wildcard $(patsubst %,%/*.c, $(PROD_DIRS)))
|
||||
HEADER_PROD_FILES := $(wildcard $(patsubst %,%/*.h, $(PROD_DIRS)))
|
||||
PROD_INC_DIRS=-I$(PROD_DIR) -I$(SHARED_DIR) -I$(RES_DIR)
|
||||
|
||||
TEST_EXEC = main_test
|
||||
TEST_DIRS := $(TEST_DIR) $(SHARED_DIR) $(RES_DIR) $(UNITY_FOLDER)
|
||||
TEST_FILES := $(wildcard $(patsubst %,%/*.c, $(TEST_DIRS)))
|
||||
HEADER_TEST_FILES := $(wildcard $(patsubst %,%/*.h, $(TEST_DIRS)))
|
||||
TEST_INC_DIRS=-I$(TEST_DIR) -I$(SHARED_DIR) -I$(UNITY_FOLDER) -I$(RES_DIR)
|
||||
|
||||
CC=gcc
|
||||
SYMBOLS=-Wall -Werror -g -O0 -std=c99
|
||||
TEST_SYMBOLS=$(SYMBOLS) -DTEST -DUNITY_USE_MODULE_SETUP_TEARDOWN
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
all: $(PROD_EXEC)
|
||||
|
||||
$(PROD_EXEC): Makefile $(PROD_FILES) $(HEADER_FILES)
|
||||
$(CC) $(PROD_INC_DIRS) $(SYMBOLS) $(PROD_FILES) -o $(BUILD_DIR)/$(PROD_EXEC)
|
||||
|
||||
$(TEST_EXEC): Makefile $(TEST_FILES) $(HEADER_FILES)
|
||||
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(BUILD_DIR)/$(TEST_EXEC)
|
||||
|
||||
run: $(PROD_EXEC)
|
||||
@./$(BUILD_DIR)/$(PROD_EXEC)
|
||||
|
||||
test: $(TEST_EXEC)
|
||||
@./$(BUILD_DIR)/$(TEST_EXEC)
|
||||
|
||||
clean:
|
||||
rm -f $(BUILD_DIR)/$(PROD_EXEC)
|
||||
rm -f $(BUILD_DIR)/$(TEST_EXEC)
|
||||
278
C/C3 Watch/ResourceDetector/list.c
Normal file
278
C/C3 Watch/ResourceDetector/list.c
Normal file
@@ -0,0 +1,278 @@
|
||||
/* **********************************************
|
||||
* generic linked list in plain c
|
||||
* author: Freddy Hurkmans
|
||||
* date: dec 20, 2014
|
||||
* **********************************************/
|
||||
|
||||
/* ******************************************************************************
|
||||
* This list is designed using object oriented ideas, but is implemented in c.
|
||||
*
|
||||
* The idea is: you construct a list for a certain data structure (say: mystruct):
|
||||
* list_admin* mylist = construct_list(sizeof(mystruct))
|
||||
* mylist contains private data for this list implementation. You need not worry
|
||||
* about it, only give it as first parameter to each list method.
|
||||
*
|
||||
* This means you can have multiple lists at the same time, just make sure you
|
||||
* give the right list_admin structure to the list function.
|
||||
* When you're done with your list, just call the destructor: destruct_list(&mylist)
|
||||
* The destructor automatically deletes remaining list elements and the list administration.
|
||||
*
|
||||
* As this list implementation keeps its own administration in list_admin, you need
|
||||
* not worry about next pointers and such. Your structure doesn't even need pointers
|
||||
* to itself, you only need to worry about data. A valid struct could thus be:
|
||||
* typedef struct
|
||||
* {
|
||||
* int nr;
|
||||
* char text[100];
|
||||
* } mystruct;
|
||||
*
|
||||
* Adding data to the list is done using list_add_* methods, such as list_add_tail,
|
||||
* which adds data to the end of the list:
|
||||
* mystruct data = {10, "hello world!"};
|
||||
* int result = list_add_tail(mylist, &data);
|
||||
* You don't have to provide the size of your struct, you've already done that in
|
||||
* the destructor. If result < 0 list_add_* has failed (either a parameter problem
|
||||
* or malloc didn't give memory).
|
||||
*
|
||||
* You can get a pointer to your data using list_get_*, e.g. get the 2nd element:
|
||||
* mystruct* dataptr = list_get_element(admin, 1);
|
||||
* or get the last element:
|
||||
* mystruct* dataptr = list_get_last(admin);
|
||||
* If dataptr is not NULL it points to the correct data, else the operation failed.
|
||||
*
|
||||
* Searching for data in your list can be done with list_index_of*. list_index_of
|
||||
* compares the data in each list item to the given data. If they are the same, it
|
||||
* returns the index. If you want to search for an element with a certain value for
|
||||
* nr or text (see mystruct) you can implement your own compare function and use
|
||||
* list_index_of_special (check memcmp for required return values):
|
||||
* int mycompare(void* p1, void* p2, size_t size)
|
||||
* {
|
||||
* // this example doesn't need size!
|
||||
* mystruct* org = (mystruct*)p1;
|
||||
* int* nr = (int*)p2;
|
||||
* return org->nr - nr; // return 0 if they are the same
|
||||
* }
|
||||
* Say you want to search for an element that has nr 10:
|
||||
* int nr = 10;
|
||||
* int index = list_index_of_special(mylist, &nr, mycompare);
|
||||
* As noted earlier: mycompare must have the same prototype as memcmp. In fact:
|
||||
* list_index_of is a shortcut for list_index_of_special(mylist, data, memcmp).
|
||||
*
|
||||
* Finally you can delete items with list_delete_*. They should work rather
|
||||
* straight forward. If they succeed they return 0. You don't have to delete
|
||||
* all items before destructing your list.
|
||||
*
|
||||
* ******************************************************************************/
|
||||
|
||||
|
||||
#include <string.h> /* for memcmp and memcpy */
|
||||
|
||||
#include "list.h"
|
||||
|
||||
static size_t data_size(const list_admin* admin);
|
||||
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index);
|
||||
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index);
|
||||
static void remove_first_element(list_admin* admin);
|
||||
static int remove_non_first_element(list_admin* admin, size_t index);
|
||||
|
||||
/* **********************************************
|
||||
* Constructor / destructor
|
||||
* **********************************************/
|
||||
list_admin* construct_list(size_t element_size)
|
||||
{
|
||||
list_admin* admin = malloc(sizeof(*admin));
|
||||
if (admin != NULL)
|
||||
{
|
||||
admin->head = NULL;
|
||||
admin->element_size = element_size;
|
||||
admin->nr_elements = 0;
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
void destruct_list(list_admin** admin)
|
||||
{
|
||||
if ((admin != NULL) && (*admin != NULL))
|
||||
{
|
||||
while ((*admin)->head != NULL)
|
||||
{
|
||||
list_head* temp = (*admin)->head;
|
||||
(*admin)->head = (*admin)->head->next;
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
}
|
||||
free(*admin);
|
||||
*admin = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* **********************************************
|
||||
* Public functions
|
||||
* **********************************************/
|
||||
int list_get_nr_elements(list_admin* admin)
|
||||
{
|
||||
int nr_elements = -1;
|
||||
if (admin != NULL)
|
||||
{
|
||||
nr_elements = admin->nr_elements;
|
||||
}
|
||||
return nr_elements;
|
||||
}
|
||||
|
||||
int list_add_tail(list_admin* admin, const void* data)
|
||||
{
|
||||
int result = -1;
|
||||
if ((admin != NULL) && (data != NULL))
|
||||
{
|
||||
list_head* new = malloc(data_size(admin));
|
||||
if (new != NULL)
|
||||
{
|
||||
result = 0;
|
||||
new->next = NULL;
|
||||
memcpy(new+1, data, admin->element_size);
|
||||
|
||||
if (admin->head == NULL)
|
||||
{
|
||||
admin->head = new;
|
||||
}
|
||||
else
|
||||
{
|
||||
list_head* temp = get_guaranteed_list_head_of_element_n(admin, admin->nr_elements-1);
|
||||
temp->next = new;
|
||||
}
|
||||
|
||||
admin->nr_elements++;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void* list_get_element(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = get_list_head_of_element_n(admin, index);
|
||||
if(item != NULL)
|
||||
{
|
||||
item++; // user data is just beyond list_head, thus we must increase the pointer
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
void* list_get_last(list_admin* admin)
|
||||
{
|
||||
list_head* item = NULL;
|
||||
if (admin != NULL)
|
||||
{
|
||||
item = list_get_element(admin, admin->nr_elements-1);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
int list_index_of(list_admin* admin, const void* data)
|
||||
{
|
||||
return list_index_of_special(admin, data, memcmp);
|
||||
}
|
||||
|
||||
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr compare)
|
||||
{
|
||||
int index = -1;
|
||||
if ((admin != NULL) && (data != NULL) && (compare != NULL))
|
||||
{
|
||||
list_head* temp = admin->head;
|
||||
index = 0;
|
||||
while ((temp != NULL) && (compare(temp+1, data, admin->element_size) != 0))
|
||||
{
|
||||
temp = temp->next;
|
||||
index++;
|
||||
}
|
||||
if (temp == NULL)
|
||||
{
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int list_delete_item(list_admin* admin, size_t index)
|
||||
{
|
||||
int result = -1;
|
||||
if ((admin != NULL) && (admin->head != NULL) && (index < admin->nr_elements))
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
result = 0;
|
||||
remove_first_element(admin);
|
||||
}
|
||||
else
|
||||
{
|
||||
result = remove_non_first_element(admin, index);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int list_delete_last(list_admin* admin)
|
||||
{
|
||||
int result = -1;
|
||||
if (admin != NULL)
|
||||
{
|
||||
result = list_delete_item(admin, admin->nr_elements - 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/* **********************************************
|
||||
* Private functions
|
||||
* **********************************************/
|
||||
static size_t data_size(const list_admin* admin)
|
||||
{
|
||||
return admin->element_size + sizeof(list_head);
|
||||
}
|
||||
|
||||
static list_head* get_guaranteed_list_head_of_element_n(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = admin->head;
|
||||
for (size_t i = 0; (i < index) && (item != NULL); i++)
|
||||
{
|
||||
item = item->next;
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
static list_head* get_list_head_of_element_n(list_admin* admin, size_t index)
|
||||
{
|
||||
list_head* item = NULL;
|
||||
if ((admin != NULL) && (index < admin->nr_elements))
|
||||
{
|
||||
item = get_guaranteed_list_head_of_element_n(admin, index);
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
static void remove_first_element(list_admin* admin)
|
||||
{
|
||||
list_head* temp = admin->head;
|
||||
admin->head = admin->head->next;
|
||||
free(temp);
|
||||
temp = NULL;
|
||||
admin->nr_elements--;
|
||||
}
|
||||
|
||||
static int remove_non_first_element(list_admin* admin, size_t index)
|
||||
{
|
||||
int result = -1;
|
||||
if (index > 0)
|
||||
{
|
||||
list_head* temp = get_list_head_of_element_n(admin, index-1);
|
||||
if ((temp != NULL) && (temp->next != NULL)) // to remove element n, element n-1 and n must exist
|
||||
{
|
||||
result = 0;
|
||||
list_head* to_delete = temp->next;
|
||||
temp->next = to_delete->next;
|
||||
free(to_delete);
|
||||
to_delete = NULL;
|
||||
admin->nr_elements--;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
52
C/C3 Watch/ResourceDetector/list.h
Normal file
52
C/C3 Watch/ResourceDetector/list.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct list_head
|
||||
{
|
||||
struct list_head* next;
|
||||
} list_head;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct list_head* head;
|
||||
size_t element_size;
|
||||
size_t nr_elements;
|
||||
} list_admin;
|
||||
|
||||
typedef int (*CompareFuncPtr)(const void*, const void*, size_t);
|
||||
|
||||
// call the constructor before using the list:
|
||||
// list_admin* mylist = construct_list(sizeof(mystruct));
|
||||
// if mylist equals NULL, no memory could be allocated. Please don't
|
||||
// mess with the admin data, this can corrupt your data.
|
||||
list_admin* construct_list(size_t element_size);
|
||||
|
||||
// call the destructor when you're done, pass the list administration
|
||||
// as referenced parameter (the variable will be set to NULL).
|
||||
void destruct_list(list_admin** admin);
|
||||
|
||||
// Reads the number of elements in your list. Returns -1 in case of
|
||||
// errors, else the number of elements.
|
||||
int list_get_nr_elements(list_admin* admin);
|
||||
|
||||
// Add data to the end of the list. Returns -1 in case of errors, else 0
|
||||
int list_add_tail(list_admin* admin, const void* data);
|
||||
|
||||
// Returns a pointer to the requested element. Returns NULL in case of
|
||||
// errors (such as: the element does not exist).
|
||||
void* list_get_element(list_admin* admin, size_t index);
|
||||
void* list_get_last(list_admin* admin);
|
||||
|
||||
// Returns the index to the first found list element that's equal to data,
|
||||
// or -1 in case of errors (such as: not found).
|
||||
int list_index_of(list_admin* admin, const void* data);
|
||||
|
||||
// Returns the index to the first found list element for which cmp says it's,
|
||||
// equal to data, or -1 in case of errors (such as: not found). cmp must behave
|
||||
// just like memcmp, i.e.: return 0 when the data matches.
|
||||
int list_index_of_special(list_admin* admin, const void* data, CompareFuncPtr cmp);
|
||||
|
||||
// Delete an item in the list. Returns -1 in case of errors, else 0.
|
||||
int list_delete_item(list_admin* admin, size_t index);
|
||||
int list_delete_last(list_admin* admin);
|
||||
270
C/C3 Watch/ResourceDetector/resource_detector.c
Normal file
270
C/C3 Watch/ResourceDetector/resource_detector.c
Normal file
@@ -0,0 +1,270 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
//#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "resource_detector.h"
|
||||
|
||||
#undef malloc
|
||||
#undef free
|
||||
#undef main
|
||||
#undef fopen
|
||||
#undef fclose
|
||||
|
||||
#include "list.h"
|
||||
|
||||
#define MAGIC_CODE 0x78563412
|
||||
|
||||
#define ADDR(addr,offset) ((addr) + (offset))
|
||||
#define SET_MAGIC_CODE(addr,offset) *((int*) ADDR(addr,offset)) = MAGIC_CODE
|
||||
#define MAGIC_CODE_OK(addr,offset) (*((int*) ADDR(addr,offset)) == MAGIC_CODE)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char* addr;
|
||||
unsigned int size;
|
||||
const char* file;
|
||||
unsigned int line;
|
||||
} mem_data;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
FILE* addr;
|
||||
const char* file_to_open;
|
||||
const char* mode;
|
||||
const char* file;
|
||||
unsigned int line;
|
||||
} file_data;
|
||||
|
||||
static list_admin* memlist = NULL;
|
||||
static list_admin* filelist = NULL;
|
||||
|
||||
static int memory_compare(const void* meminfo, const void* address, size_t size)
|
||||
{
|
||||
mem_data* info = (mem_data*)meminfo;
|
||||
char* addr = (char*)address;
|
||||
return info->addr - addr;
|
||||
}
|
||||
|
||||
static int file_compare(const void* fileinfo, const void* address, size_t size)
|
||||
{
|
||||
file_data* info = (file_data*)fileinfo;
|
||||
FILE* addr = (FILE*)address;
|
||||
return info->addr - addr;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
invalidate (mem_data* info)
|
||||
{
|
||||
char* user_addr;
|
||||
char* raw_addr;
|
||||
unsigned int size;
|
||||
|
||||
user_addr = info->addr;
|
||||
size = info->size;
|
||||
raw_addr = ADDR (user_addr, -sizeof(int));
|
||||
|
||||
if (!MAGIC_CODE_OK(user_addr, -sizeof(int)) || !MAGIC_CODE_OK(user_addr, size))
|
||||
{
|
||||
fprintf (stderr, "ERROR: addr %p (%s, line %d): out-of-bound access\n", (void*)user_addr, info->file, info->line);
|
||||
}
|
||||
|
||||
memset (raw_addr, 0xff, size + (2 * sizeof(int)));
|
||||
free (raw_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* replacement of malloc
|
||||
*/
|
||||
extern void*
|
||||
xmalloc (unsigned int size, const char* file, unsigned int line)
|
||||
{
|
||||
char* raw_addr = malloc (size + (2 * sizeof(int)));
|
||||
char* user_addr;
|
||||
mem_data info = {NULL, 0, NULL, 0};
|
||||
|
||||
if (raw_addr == NULL)
|
||||
{
|
||||
fprintf (stderr, "ERROR: malloc failed for %d bytes (%s, line %d)\n", size, file, line);
|
||||
return (NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
user_addr = ADDR (raw_addr, sizeof (int));
|
||||
SET_MAGIC_CODE (raw_addr, 0);
|
||||
SET_MAGIC_CODE (user_addr, size);
|
||||
|
||||
info.addr = user_addr;
|
||||
info.size = size;
|
||||
info.file = file;
|
||||
info.line = line;
|
||||
list_add_tail(memlist, &info);
|
||||
}
|
||||
return ((void*) user_addr);
|
||||
}
|
||||
|
||||
/*
|
||||
* replacement of free
|
||||
*/
|
||||
extern void
|
||||
xfree (void* addr, const char* filename, int linenr)
|
||||
{
|
||||
char* user_addr = (char*) addr;
|
||||
mem_data* info = NULL;
|
||||
|
||||
/* check if allocated memory is in our list and retrieve its info */
|
||||
int index = list_index_of_special(memlist, addr, memory_compare);
|
||||
info = list_get_element(memlist, index);
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
fprintf (stderr, "ERROR: trying to free memory that was not malloc-ed (addr %p) in %s : %d\n", (void*)user_addr, filename, linenr);
|
||||
return;
|
||||
}
|
||||
|
||||
invalidate (info);
|
||||
list_delete_item(memlist, index);
|
||||
}
|
||||
|
||||
static void
|
||||
print_empty_lines(int n)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void set_colour_red(void)
|
||||
{
|
||||
fprintf(stderr, "\033[10;31m");
|
||||
}
|
||||
static void set_colour_gray(void)
|
||||
{
|
||||
fprintf(stderr, "\033[22;37m");
|
||||
}
|
||||
static void
|
||||
print_line(void)
|
||||
{
|
||||
fprintf (stderr, "---------------------------------------------------------\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_not_good(void)
|
||||
{
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
set_colour_red();
|
||||
fprintf (stderr, " # # ###\n");
|
||||
fprintf (stderr, " ## # #### ##### #### #### #### ##### ###\n");
|
||||
fprintf (stderr, " # # # # # # # # # # # # # # ###\n");
|
||||
fprintf (stderr, " # # # # # # # # # # # # # # \n");
|
||||
fprintf (stderr, " # # # # # # # ### # # # # # # \n");
|
||||
fprintf (stderr, " # ## # # # # # # # # # # # ###\n");
|
||||
fprintf (stderr, " # # #### # #### #### #### ##### ###\n");
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
}
|
||||
|
||||
/*
|
||||
* writes all info of the unallocated memory
|
||||
*/
|
||||
static void
|
||||
resource_detection (void)
|
||||
{
|
||||
time_t now = time (NULL);
|
||||
|
||||
int forgotten_frees = list_get_nr_elements(memlist);
|
||||
int nr_files_open = list_get_nr_elements(filelist);
|
||||
|
||||
if ((forgotten_frees > 0) || (nr_files_open > 0))
|
||||
{
|
||||
print_empty_lines(15);
|
||||
}
|
||||
|
||||
if (forgotten_frees > 0)
|
||||
{
|
||||
mem_data* info = NULL;
|
||||
print_line();
|
||||
fprintf (stderr, "Memory Leak Summary, generated: %s", ctime (&now));
|
||||
print_not_good();
|
||||
set_colour_red();
|
||||
while((info = list_get_element(memlist, 0)) != NULL)
|
||||
{
|
||||
fprintf (stderr, "forgot to free address: %p (%d bytes) that was allocated in: %s on line: %d\n",
|
||||
(void*)info->addr, info->size, info->file, info->line);
|
||||
list_delete_item(memlist, 0);
|
||||
}
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
print_empty_lines(1);
|
||||
}
|
||||
|
||||
if (nr_files_open > 0)
|
||||
{
|
||||
file_data* info = NULL;
|
||||
print_line();
|
||||
fprintf (stderr, "File Management Summary, generated: %s", ctime (&now));
|
||||
print_not_good();
|
||||
set_colour_red();
|
||||
while((info = list_get_element(filelist, 0)) != NULL)
|
||||
{
|
||||
fprintf (stderr, "forgot to close file: %s (ptr %p, mode \"%s\") that was opened from: %s on line: %d\n",
|
||||
info->file_to_open, (void*)(info->addr), info->mode, info->file, info->line);
|
||||
list_delete_item(filelist, 0);
|
||||
}
|
||||
set_colour_gray();
|
||||
print_line();
|
||||
print_empty_lines(1);
|
||||
}
|
||||
if ((forgotten_frees == 0) && (nr_files_open == 0))
|
||||
{
|
||||
printf ("\nResource checks: OK\n\n");
|
||||
}
|
||||
|
||||
destruct_list(&memlist);
|
||||
destruct_list(&filelist);
|
||||
}
|
||||
|
||||
extern FILE*
|
||||
xfopen (const char* file_to_open, const char* mode, const char* filename, int linenr)
|
||||
{
|
||||
file_data info = {0};
|
||||
info.addr = fopen(file_to_open, mode);
|
||||
if (info.addr != NULL)
|
||||
{
|
||||
info.file_to_open = file_to_open;
|
||||
info.mode = mode;
|
||||
info.file = filename;
|
||||
info.line = linenr;
|
||||
list_add_tail(filelist, &info);
|
||||
}
|
||||
return info.addr;
|
||||
}
|
||||
|
||||
extern int
|
||||
xfclose(FILE* fptr, const char* filename, int linenr)
|
||||
{
|
||||
int index = list_index_of_special(filelist, fptr, file_compare);
|
||||
if (index < 0)
|
||||
{
|
||||
fprintf (stderr, "ERROR: trying to close an unopened file in %s on line number %d.\n", filename, linenr);
|
||||
return -1;
|
||||
}
|
||||
list_delete_item(filelist, index);
|
||||
return (fclose (fptr));
|
||||
}
|
||||
|
||||
extern int
|
||||
main (int argc, char* argv[])
|
||||
{
|
||||
atexit (resource_detection);
|
||||
memlist = construct_list(sizeof(mem_data));
|
||||
filelist = construct_list(sizeof(file_data));
|
||||
|
||||
return (xmain (argc, argv));
|
||||
}
|
||||
18
C/C3 Watch/ResourceDetector/resource_detector.h
Normal file
18
C/C3 Watch/ResourceDetector/resource_detector.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef RESOURCE_DETECTOR_H
|
||||
#define RESOURCE_DETECTOR_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define main xmain
|
||||
#define malloc(size) xmalloc ((size), (__FILE__), (__LINE__))
|
||||
#define free(addr) xfree ((addr), __FILE__, __LINE__)
|
||||
#define fopen(name,mode) xfopen ((name),(mode), __FILE__, __LINE__)
|
||||
#define fclose(fptr) xfclose ((fptr), __FILE__, __LINE__)
|
||||
|
||||
extern int xmain(int argc, char* argv[]);
|
||||
extern void* xmalloc(unsigned int size, const char* file, unsigned int line);
|
||||
extern void xfree(void* addr, const char* filename, int linenr);
|
||||
extern FILE* xfopen(const char* file_to_open, const char* mode, const char* filename, int linenr);
|
||||
extern int xfclose(FILE* fptr, const char* filename, int linenr);
|
||||
|
||||
#endif
|
||||
28
C/C3 Watch/ResourceDetector/test/Makefile
Normal file
28
C/C3 Watch/ResourceDetector/test/Makefile
Normal file
@@ -0,0 +1,28 @@
|
||||
UNITY_FOLDER=../Unity
|
||||
TEST_INC_DIRS=$(INC_DIRS) -I$(UNITY_FOLDER)
|
||||
|
||||
TEST_FILES=$(UNITY_FOLDER)/unity.c \
|
||||
list_test.c \
|
||||
list.c
|
||||
|
||||
HEADER_FILES=*.h
|
||||
|
||||
TEST = list_test
|
||||
|
||||
CC=gcc
|
||||
|
||||
SYMBOLS=-Wall -Werror -pedantic -O0 -ggdb -std=c99
|
||||
TEST_SYMBOLS=$(SYMBOLS) -DTEST
|
||||
|
||||
.PHONY: clean test
|
||||
|
||||
all: $(TEST)
|
||||
|
||||
$(TEST): Makefile $(TEST_FILES) $(HEADER_FILES)
|
||||
$(CC) $(TEST_INC_DIRS) $(TEST_SYMBOLS) $(TEST_FILES) -o $(TEST)
|
||||
|
||||
clean:
|
||||
rm -f list $(TEST)
|
||||
|
||||
test: $(TEST)
|
||||
@valgrind ./$(TEST)
|
||||
300
C/C3 Watch/ResourceDetector/test/list_test.c
Normal file
300
C/C3 Watch/ResourceDetector/test/list_test.c
Normal file
@@ -0,0 +1,300 @@
|
||||
#include <string.h> /* for memcmp */
|
||||
|
||||
#include "list.h"
|
||||
#include "unity.h"
|
||||
|
||||
// I rather dislike keeping line numbers updated, so I made my own macro to ditch the line number
|
||||
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||
|
||||
static list_admin* mylist = NULL;
|
||||
typedef struct
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
} test_struct;
|
||||
|
||||
// compare function that returns 0 if test_struct.i matches, it ignores .j
|
||||
static int compare_test_func(const void* p1, const void* p2, size_t size)
|
||||
{
|
||||
size = size; // to prevent warnings
|
||||
const test_struct* data1 = (const test_struct*)p1;
|
||||
const test_struct* data2 = (const test_struct*)p2;
|
||||
return data1->i - data2->i;
|
||||
}
|
||||
// check n items in list against verify_data
|
||||
// IMPORTANT: this function must check using list_get_element,
|
||||
// else the test for that function is no longer useful
|
||||
static void check_n_list_elements_ok(list_admin* admin, int nr_items, const test_struct* verify_data)
|
||||
{
|
||||
for(int i = 0; i < nr_items; i++)
|
||||
{
|
||||
test_struct* ptr = list_get_element(admin, i);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(verify_data+i, ptr, sizeof(*ptr)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
// This is run before EACH test
|
||||
mylist = construct_list(sizeof(test_struct));
|
||||
TEST_ASSERT_NOT_NULL(mylist);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
destruct_list(&mylist);
|
||||
TEST_ASSERT_NULL(mylist);
|
||||
}
|
||||
|
||||
static void test_ConstructList(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(sizeof(test_struct), mylist->element_size);
|
||||
TEST_ASSERT_EQUAL(0, mylist->nr_elements);
|
||||
}
|
||||
|
||||
static void test_NrElements_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_get_nr_elements(NULL));
|
||||
}
|
||||
|
||||
static void test_AddData_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_add_tail(mylist, NULL));
|
||||
TEST_ASSERT_EQUAL(-1, list_add_tail(NULL, mylist));
|
||||
}
|
||||
|
||||
static void test_AddData(void)
|
||||
{
|
||||
test_struct data = {3, 4};
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data));
|
||||
|
||||
TEST_ASSERT_NOT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(1, list_get_nr_elements(mylist));
|
||||
list_head* head = mylist->head;
|
||||
test_struct* element = (test_struct*)(head+1);
|
||||
TEST_ASSERT_EQUAL(data.i, element->i);
|
||||
TEST_ASSERT_EQUAL(data.j, element->j);
|
||||
}
|
||||
|
||||
static void test_Add2PiecesOfData(void)
|
||||
{
|
||||
test_struct data1 = {8, 9};
|
||||
test_struct data2 = {-3, -4};
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data1));
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &data2));
|
||||
|
||||
TEST_ASSERT_NOT_NULL(mylist->head);
|
||||
TEST_ASSERT_NOT_NULL(mylist->head->next);
|
||||
TEST_ASSERT_EQUAL(2, list_get_nr_elements(mylist));
|
||||
list_head* head = mylist->head->next;
|
||||
test_struct* element = (test_struct*)(head+1);
|
||||
TEST_ASSERT_EQUAL(data2.i, element->i);
|
||||
TEST_ASSERT_EQUAL(data2.j, element->j);
|
||||
}
|
||||
|
||||
static void test_GetElement_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(list_get_element(NULL, 0));
|
||||
}
|
||||
|
||||
static void test_GetElement(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
|
||||
const int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data); // checks using list_get_element
|
||||
|
||||
TEST_ASSERT_NULL(list_get_element(mylist, nr_elements));
|
||||
TEST_ASSERT_NULL(list_get_element(mylist, -1));
|
||||
}
|
||||
|
||||
static void test_GetLast_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_NULL(list_get_last(NULL));
|
||||
}
|
||||
|
||||
static void test_GetLast(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}};
|
||||
const int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
TEST_ASSERT_NULL(list_get_last(mylist));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
test_struct* ptr = list_get_last(mylist);
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
TEST_ASSERT_EQUAL(0, memcmp(&(data[i]), ptr, sizeof(*ptr)));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_IndexOf_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, NULL));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(NULL, mylist));
|
||||
}
|
||||
|
||||
static void test_IndexOf(void)
|
||||
{
|
||||
const test_struct real_data[] = {{8, 9}, {-3, -4}, {21, 56}};
|
||||
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
|
||||
const test_struct false_data[] = {{-3, 9}, {8, 56}, {21, -4}, {0, 0}};
|
||||
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(real_data[i])));
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(i, list_index_of(mylist, &(real_data[i])));
|
||||
}
|
||||
for(int i = 0; i < nr_false_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of(mylist, &(false_data[i])));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_IndexOfSpecial_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, NULL, compare_test_func));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(NULL, mylist, compare_test_func));
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, mylist, NULL));
|
||||
}
|
||||
|
||||
static void test_IndexOfSpecial(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}}; // data in list
|
||||
const test_struct real_data[] = {{8, -4}, {-3, 56}, {21, 9}}; // data to search for (i equals)
|
||||
const int nr_real_elements = sizeof(real_data)/sizeof(real_data[0]);
|
||||
const test_struct false_data[] = {{-2, 9}, {9, -4}, {22, 56}, {0, 0}}; // data that doesn't exist
|
||||
const int nr_false_elements = sizeof(false_data)/sizeof(false_data[0]);
|
||||
|
||||
// first make sure our compare function works
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, compare_test_func(&(data[i]), &(real_data[i]), 0));
|
||||
for (int j = 0; j < nr_false_elements; j++)
|
||||
{
|
||||
TEST_ASSERT_NOT_EQUAL(0, compare_test_func(&(data[i]), &(false_data[j]), 0))
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
for(int i = 0; i < nr_real_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(i, list_index_of_special(mylist, &(real_data[i]), compare_test_func));
|
||||
}
|
||||
for(int i = 0; i < nr_false_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_index_of_special(mylist, &(false_data[i]), compare_test_func));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_DeleteItem_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(NULL, 0));
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, -1));
|
||||
}
|
||||
|
||||
static void test_DeleteItem(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
const test_struct data_noFirst[] = {{-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
const test_struct data_noLast[] = {{-3, -4}, {21, 56}, {0, 0}};
|
||||
const test_struct data_noMiddle[] = {{-3, -4}, {0, 0}};
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_item(mylist, 0));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 0));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noFirst);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, nr_elements-1));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noLast);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, list_delete_item(mylist, 1));
|
||||
nr_elements--;
|
||||
TEST_ASSERT_EQUAL(nr_elements, list_get_nr_elements(mylist));
|
||||
|
||||
check_n_list_elements_ok(mylist, nr_elements, data_noMiddle);
|
||||
}
|
||||
|
||||
static void test_DeleteLast_parameters(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_last(NULL));
|
||||
}
|
||||
|
||||
static void test_DeleteLast(void)
|
||||
{
|
||||
const test_struct data[] = {{8, 9}, {-3, -4}, {21, 56}, {0, 0}, {12, 12345}};
|
||||
int nr_elements = sizeof(data)/sizeof(data[0]);
|
||||
|
||||
TEST_ASSERT_EQUAL(-1, list_delete_last(mylist));
|
||||
for(int i = 0; i < nr_elements; i++)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_add_tail(mylist, &(data[i])));
|
||||
}
|
||||
|
||||
for (int i = nr_elements-1; i >= 0; i--)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(0, list_delete_last(mylist));
|
||||
TEST_ASSERT_EQUAL(i, list_get_nr_elements(mylist));
|
||||
check_n_list_elements_ok(mylist, i, data);
|
||||
}
|
||||
|
||||
TEST_ASSERT_NULL(mylist->head);
|
||||
TEST_ASSERT_EQUAL(0, list_get_nr_elements(mylist));
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
UnityBegin();
|
||||
|
||||
MY_RUN_TEST(test_ConstructList);
|
||||
MY_RUN_TEST(test_NrElements_parameters);
|
||||
MY_RUN_TEST(test_AddData_parameters);
|
||||
MY_RUN_TEST(test_AddData);
|
||||
MY_RUN_TEST(test_Add2PiecesOfData);
|
||||
MY_RUN_TEST(test_GetElement_parameters);
|
||||
MY_RUN_TEST(test_GetElement);
|
||||
MY_RUN_TEST(test_GetLast_parameters);
|
||||
MY_RUN_TEST(test_GetLast);
|
||||
MY_RUN_TEST(test_IndexOf_parameters);
|
||||
MY_RUN_TEST(test_IndexOf);
|
||||
MY_RUN_TEST(test_IndexOfSpecial_parameters);
|
||||
MY_RUN_TEST(test_IndexOfSpecial);
|
||||
MY_RUN_TEST(test_DeleteItem_parameters);
|
||||
MY_RUN_TEST(test_DeleteItem);
|
||||
MY_RUN_TEST(test_DeleteLast_parameters);
|
||||
MY_RUN_TEST(test_DeleteLast);
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
// MY_RUN_TEST();
|
||||
|
||||
return UnityEnd();
|
||||
}
|
||||
841
C/C3 Watch/Unity/unity.c
Normal file
841
C/C3 Watch/Unity/unity.c
Normal file
@@ -0,0 +1,841 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#include "unity.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_CHAR('\n'); longjmp(Unity.AbortFrame, 1); }
|
||||
/// return prematurely if we are already in failure or ignore state
|
||||
#define UNITY_SKIP_EXECUTION { if ((Unity.CurrentTestFailed != 0) || (Unity.CurrentTestIgnored != 0)) {return;} }
|
||||
#define UNITY_PRINT_EOL { UNITY_OUTPUT_CHAR('\n'); }
|
||||
|
||||
struct _Unity Unity = { 0 };
|
||||
|
||||
const char* UnityStrNull = "NULL";
|
||||
const char* UnityStrSpacer = ". ";
|
||||
const char* UnityStrExpected = " Expected ";
|
||||
const char* UnityStrWas = " Was ";
|
||||
const char* UnityStrTo = " To ";
|
||||
const char* UnityStrElement = " Element ";
|
||||
const char* UnityStrMemory = " Memory Mismatch";
|
||||
const char* UnityStrDelta = " Values Not Within Delta ";
|
||||
const char* UnityStrPointless= " You Asked Me To Compare Nothing, Which Was Pointless.";
|
||||
const char* UnityStrNullPointerForExpected= " Expected pointer to be NULL";
|
||||
const char* UnityStrNullPointerForActual = " Actual pointer was NULL";
|
||||
|
||||
//-----------------------------------------------
|
||||
// Pretty Printers & Test Result Output Handlers
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string)
|
||||
{
|
||||
const char* pch = string;
|
||||
|
||||
if (pch != NULL)
|
||||
{
|
||||
while (*pch)
|
||||
{
|
||||
// printable characters plus CR & LF are printed
|
||||
if ((*pch <= 126) && (*pch >= 32))
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(*pch);
|
||||
}
|
||||
//write escaped carriage returns
|
||||
else if (*pch == 13)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UNITY_OUTPUT_CHAR('r');
|
||||
}
|
||||
//write escaped line feeds
|
||||
else if (*pch == 10)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UNITY_OUTPUT_CHAR('n');
|
||||
}
|
||||
// unprintable characters are shown as codes
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\\');
|
||||
UnityPrintNumberHex((_U_SINT)*pch, 2);
|
||||
}
|
||||
pch++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
UnityPrintNumber(number);
|
||||
}
|
||||
else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT)
|
||||
{
|
||||
UnityPrintNumberUnsigned((_U_UINT)number);
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrintNumberHex((_U_UINT)number, (style & 0x000F) << 1);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumber(const _U_SINT number_to_print)
|
||||
{
|
||||
_U_SINT divisor = 1;
|
||||
_U_SINT next_divisor;
|
||||
_U_SINT number = number_to_print;
|
||||
|
||||
if (number < 0)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('-');
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
/// basically do an itoa using as little ram as possible
|
||||
void UnityPrintNumberUnsigned(const _U_UINT number)
|
||||
{
|
||||
_U_UINT divisor = 1;
|
||||
_U_UINT next_divisor;
|
||||
|
||||
// figure out initial divisor
|
||||
while (number / divisor > 9)
|
||||
{
|
||||
next_divisor = divisor * 10;
|
||||
if (next_divisor > divisor)
|
||||
divisor = next_divisor;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
// now mod and print, then divide divisor
|
||||
do
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10)));
|
||||
divisor /= 10;
|
||||
}
|
||||
while (divisor > 0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintNumberHex(const _U_UINT number, const char nibbles_to_print)
|
||||
{
|
||||
_U_UINT nibble;
|
||||
char nibbles = nibbles_to_print;
|
||||
UNITY_OUTPUT_CHAR('0');
|
||||
UNITY_OUTPUT_CHAR('x');
|
||||
|
||||
while (nibbles > 0)
|
||||
{
|
||||
nibble = (number >> (--nibbles << 2)) & 0x0000000F;
|
||||
if (nibble <= 9)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('0' + nibble));
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintMask(const _U_UINT mask, const _U_UINT number)
|
||||
{
|
||||
_U_UINT current_bit = (_U_UINT)1 << (UNITY_INT_WIDTH - 1);
|
||||
_US32 i;
|
||||
|
||||
for (i = 0; i < UNITY_INT_WIDTH; i++)
|
||||
{
|
||||
if (current_bit & mask)
|
||||
{
|
||||
if (current_bit & number)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('1');
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('0');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('X');
|
||||
}
|
||||
current_bit = current_bit >> 1;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
void UnityPrintFloat(_UF number)
|
||||
{
|
||||
char TempBuffer[32];
|
||||
sprintf(TempBuffer, "%.6f", number);
|
||||
UnityPrint(TempBuffer);
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityPrint(file);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrintNumber(line);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UnityPrint(Unity.CurrentTestName);
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL:");
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityConcludeTest(void)
|
||||
{
|
||||
if (Unity.CurrentTestIgnored)
|
||||
{
|
||||
Unity.TestIgnores++;
|
||||
}
|
||||
else if (!Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber);
|
||||
UnityPrint("PASS");
|
||||
UNITY_PRINT_EOL;
|
||||
}
|
||||
else
|
||||
{
|
||||
Unity.TestFailures++;
|
||||
}
|
||||
|
||||
Unity.CurrentTestFailed = 0;
|
||||
Unity.CurrentTestIgnored = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAddMsgIfSpecified(const char* msg)
|
||||
{
|
||||
if (msg)
|
||||
{
|
||||
UnityPrint(UnityStrSpacer);
|
||||
UnityPrint(msg);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual)
|
||||
{
|
||||
UnityPrint(UnityStrExpected);
|
||||
if (expected != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(expected);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint(UnityStrNull);
|
||||
}
|
||||
UnityPrint(UnityStrWas);
|
||||
if (actual != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
UnityPrint(actual);
|
||||
UNITY_OUTPUT_CHAR('\'');
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint(UnityStrNull);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Assertion & Control Helpers
|
||||
//-----------------------------------------------
|
||||
|
||||
int UnityCheckArraysForNull(const void* expected, const void* actual, const UNITY_LINE_TYPE lineNumber, const char* msg)
|
||||
{
|
||||
//return true if they are both NULL
|
||||
if ((expected == NULL) && (actual == NULL))
|
||||
return 1;
|
||||
|
||||
//throw error if just expected is NULL
|
||||
if (expected == NULL)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrNullPointerForExpected);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//throw error if just actual is NULL
|
||||
if (actual == NULL)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrNullPointerForActual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//return false if neither is NULL
|
||||
return 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Assertion Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityAssertBits(const _U_SINT mask,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((mask & expected) != (mask & actual))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintMask(mask, expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintMask(mask, actual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualNumber(const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (expected != actual)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualIntArray(const _U_SINT* expected,
|
||||
const _U_SINT* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
_UU32 elements = num_elements;
|
||||
const _US8* ptr_exp = (_US8*)expected;
|
||||
const _US8* ptr_act = (_US8*)actual;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
switch(style)
|
||||
{
|
||||
case UNITY_DISPLAY_STYLE_HEX8:
|
||||
case UNITY_DISPLAY_STYLE_INT8:
|
||||
case UNITY_DISPLAY_STYLE_UINT8:
|
||||
while (elements--)
|
||||
{
|
||||
if (*ptr_exp != *ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 1;
|
||||
ptr_act += 1;
|
||||
}
|
||||
break;
|
||||
case UNITY_DISPLAY_STYLE_HEX16:
|
||||
case UNITY_DISPLAY_STYLE_INT16:
|
||||
case UNITY_DISPLAY_STYLE_UINT16:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US16*)ptr_exp != *(_US16*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US16*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 2;
|
||||
ptr_act += 2;
|
||||
}
|
||||
break;
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
case UNITY_DISPLAY_STYLE_HEX64:
|
||||
case UNITY_DISPLAY_STYLE_INT64:
|
||||
case UNITY_DISPLAY_STYLE_UINT64:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US64*)ptr_exp != *(_US64*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US64*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 8;
|
||||
ptr_act += 8;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
while (elements--)
|
||||
{
|
||||
if (*(_US32*)ptr_exp != *(_US32*)ptr_act)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_exp, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(*(_US32*)ptr_act, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_exp += 4;
|
||||
ptr_act += 4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertEqualFloatArray(const _UF* expected,
|
||||
const _UF* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 elements = num_elements;
|
||||
const _UF* ptr_expected = expected;
|
||||
const _UF* ptr_actual = actual;
|
||||
_UF diff, tol;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
diff = *ptr_expected - *ptr_actual;
|
||||
if (diff < 0.0)
|
||||
diff = 0.0 - diff;
|
||||
tol = UNITY_FLOAT_PRECISION * *ptr_expected;
|
||||
if (tol < 0.0)
|
||||
tol = 0.0 - tol;
|
||||
if (diff > tol)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(*ptr_expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintFloat(*ptr_actual);
|
||||
#else
|
||||
UnityPrint(UnityStrDelta);
|
||||
#endif
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
ptr_expected++;
|
||||
ptr_actual++;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UF diff = actual - expected;
|
||||
_UF pos_delta = delta;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if (diff < 0)
|
||||
{
|
||||
diff = 0.0f - diff;
|
||||
}
|
||||
if (pos_delta < 0)
|
||||
{
|
||||
pos_delta = 0.0f - pos_delta;
|
||||
}
|
||||
|
||||
if (pos_delta < diff)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintFloat(expected);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintFloat(actual);
|
||||
#else
|
||||
UnityPrint(UnityStrDelta);
|
||||
#endif
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertNumbersWithin( const _U_SINT delta,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT)
|
||||
{
|
||||
if (actual > expected)
|
||||
Unity.CurrentTestFailed = ((actual - expected) > delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((expected - actual) > delta);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((_U_UINT)actual > (_U_UINT)expected)
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(actual - expected) > (_U_UINT)delta);
|
||||
else
|
||||
Unity.CurrentTestFailed = ((_U_UINT)(expected - actual) > (_U_UINT)delta);
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrDelta);
|
||||
UnityPrintNumberByStyle(delta, style);
|
||||
UnityPrint(UnityStrExpected);
|
||||
UnityPrintNumberByStyle(expected, style);
|
||||
UnityPrint(UnityStrWas);
|
||||
UnityPrintNumberByStyle(actual, style);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 i;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
// if both pointers not null compare the strings
|
||||
if (expected && actual)
|
||||
{
|
||||
for (i = 0; expected[i] || actual[i]; i++)
|
||||
{
|
||||
if (expected[i] != actual[i])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected != actual)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrintExpectedAndActualStrings(expected, actual);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualStringArray( const char** expected,
|
||||
const char** actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
_UU32 i, j = 0;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
// if no elements, it's an error
|
||||
if (num_elements == 0)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
do
|
||||
{
|
||||
// if both pointers not null compare the strings
|
||||
if (expected[j] && actual[j])
|
||||
{
|
||||
for (i = 0; expected[j][i] || actual[j][i]; i++)
|
||||
{
|
||||
if (expected[j][i] != actual[j][i])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // handle case of one pointers being null (if both null, test should pass)
|
||||
if (expected[j] != actual[j])
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
if (num_elements > 1)
|
||||
{
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - j - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
}
|
||||
UnityPrintExpectedAndActualStrings((const char*)(expected[j]), (const char*)(actual[j]));
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
} while (++j < num_elements);
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
_UU32 length,
|
||||
_UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber)
|
||||
{
|
||||
unsigned char* expected_ptr = (unsigned char*)expected;
|
||||
unsigned char* actual_ptr = (unsigned char*)actual;
|
||||
_UU32 elements = num_elements;
|
||||
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
if ((elements == 0) || (length == 0))
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
UnityPrint(UnityStrPointless);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
if (UnityCheckArraysForNull((void*)expected, (void*)actual, lineNumber, msg) == 1)
|
||||
return;
|
||||
|
||||
while (elements--)
|
||||
{
|
||||
if (memcmp((const void*)expected_ptr, (const void*)actual_ptr, length) != 0)
|
||||
{
|
||||
Unity.CurrentTestFailed = 1;
|
||||
break;
|
||||
}
|
||||
expected_ptr += length;
|
||||
actual_ptr += length;
|
||||
}
|
||||
|
||||
if (Unity.CurrentTestFailed)
|
||||
{
|
||||
UnityTestResultsFailBegin(lineNumber);
|
||||
if (num_elements > 1)
|
||||
{
|
||||
UnityPrint(UnityStrElement);
|
||||
UnityPrintNumberByStyle((num_elements - elements - 1), UNITY_DISPLAY_STYLE_UINT);
|
||||
}
|
||||
UnityPrint(UnityStrMemory);
|
||||
UnityAddMsgIfSpecified(msg);
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
// Control Functions
|
||||
//-----------------------------------------------
|
||||
|
||||
void UnityFail(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("FAIL");
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
if (msg[0] != ' ')
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
}
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_FAIL_AND_BAIL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line)
|
||||
{
|
||||
UNITY_SKIP_EXECUTION;
|
||||
|
||||
UnityTestResultsBegin(Unity.TestFile, line);
|
||||
UnityPrint("IGNORE");
|
||||
if (msg != NULL)
|
||||
{
|
||||
UNITY_OUTPUT_CHAR(':');
|
||||
UNITY_OUTPUT_CHAR(' ');
|
||||
UnityPrint(msg);
|
||||
}
|
||||
UNITY_IGNORE_AND_BAIL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void setUp(void);
|
||||
void tearDown(void);
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum)
|
||||
{
|
||||
Unity.CurrentTestName = FuncName;
|
||||
Unity.CurrentTestLineNumber = FuncLineNum;
|
||||
Unity.NumberOfTests++;
|
||||
if (TEST_PROTECT())
|
||||
{
|
||||
setUp();
|
||||
Func();
|
||||
}
|
||||
if (TEST_PROTECT() && !(Unity.CurrentTestIgnored))
|
||||
{
|
||||
tearDown();
|
||||
}
|
||||
UnityConcludeTest();
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
void UnityBegin(void)
|
||||
{
|
||||
Unity.NumberOfTests = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------
|
||||
int UnityEnd(void)
|
||||
{
|
||||
UnityPrint("-----------------------");
|
||||
UNITY_PRINT_EOL;
|
||||
UnityPrintNumber(Unity.NumberOfTests);
|
||||
UnityPrint(" Tests ");
|
||||
UnityPrintNumber(Unity.TestFailures);
|
||||
UnityPrint(" Failures ");
|
||||
UnityPrintNumber(Unity.TestIgnores);
|
||||
UnityPrint(" Ignored");
|
||||
UNITY_PRINT_EOL;
|
||||
if (Unity.TestFailures == 0U)
|
||||
{
|
||||
UnityPrint("OK");
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityPrint("FAIL");
|
||||
}
|
||||
UNITY_PRINT_EOL;
|
||||
return Unity.TestFailures;
|
||||
}
|
||||
209
C/C3 Watch/Unity/unity.h
Normal file
209
C/C3 Watch/Unity/unity.h
Normal file
@@ -0,0 +1,209 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#ifndef UNITY_FRAMEWORK_H
|
||||
#define UNITY_FRAMEWORK_H
|
||||
|
||||
#define UNITY
|
||||
|
||||
#include "unity_internals.h"
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Configuration Options
|
||||
//-------------------------------------------------------
|
||||
|
||||
// Integers
|
||||
// - Unity assumes 32 bit integers by default
|
||||
// - If your compiler treats ints of a different size, define UNITY_INT_WIDTH
|
||||
|
||||
// Floats
|
||||
// - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons
|
||||
// - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT
|
||||
// - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats
|
||||
// - define UNITY_FLOAT_VERBOSE to print floating point values in errors (uses sprintf)
|
||||
|
||||
// Output
|
||||
// - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired
|
||||
|
||||
// Optimization
|
||||
// - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge
|
||||
// - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests.
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Running Macros
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0)
|
||||
|
||||
#define TEST_ABORT() {longjmp(Unity.AbortFrame, 1);}
|
||||
|
||||
#ifndef RUN_TEST
|
||||
#define RUN_TEST(func, line_num) UnityDefaultTestRun(func, #func, line_num)
|
||||
#endif
|
||||
|
||||
#define TEST_LINE_NUM (Unity.CurrentTestLineNumber)
|
||||
#define TEST_IS_IGNORED (Unity.CurrentTestIgnored)
|
||||
|
||||
#define TEST_CASE(...)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, message)
|
||||
#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL)
|
||||
#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, message)
|
||||
#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL)
|
||||
#define TEST_ONLY()
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (simple)
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Boolean
|
||||
#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE")
|
||||
#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE")
|
||||
#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE")
|
||||
#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE")
|
||||
#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL")
|
||||
#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL")
|
||||
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal")
|
||||
#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, NULL)
|
||||
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, NULL)
|
||||
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, NULL)
|
||||
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, NULL)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, NULL)
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts (with additional messages)
|
||||
//-------------------------------------------------------
|
||||
|
||||
//Boolean
|
||||
#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, message)
|
||||
#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, message)
|
||||
#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, message)
|
||||
|
||||
//Integers (of all sizes)
|
||||
#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (_UU32)(0), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(-1), (actual), __LINE__, message)
|
||||
#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((_UU32)1 << bit), (_UU32)(0), (actual), __LINE__, message)
|
||||
|
||||
//Integer Ranges (of all sizes)
|
||||
#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
|
||||
//Structs and Strings
|
||||
#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, __LINE__, message)
|
||||
|
||||
//Arrays
|
||||
#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, __LINE__, message)
|
||||
|
||||
//Floating Point (If Enabled)
|
||||
#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, __LINE__, message)
|
||||
#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, __LINE__, message)
|
||||
#endif
|
||||
356
C/C3 Watch/Unity/unity_internals.h
Normal file
356
C/C3 Watch/Unity/unity_internals.h
Normal file
@@ -0,0 +1,356 @@
|
||||
/* ==========================================
|
||||
Unity Project - A Test Framework for C
|
||||
Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams
|
||||
[Released under MIT License. Please refer to license.txt for details]
|
||||
========================================== */
|
||||
|
||||
#ifndef UNITY_INTERNALS_H
|
||||
#define UNITY_INTERNALS_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <setjmp.h>
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Int Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_INT_WIDTH
|
||||
#define UNITY_INT_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_LONG_WIDTH
|
||||
#define UNITY_LONG_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#if (UNITY_INT_WIDTH == 32)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned short _UU16;
|
||||
typedef unsigned int _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed short _US16;
|
||||
typedef signed int _US32;
|
||||
#elif (UNITY_INT_WIDTH == 16)
|
||||
typedef unsigned char _UU8;
|
||||
typedef unsigned int _UU16;
|
||||
typedef unsigned long _UU32;
|
||||
typedef signed char _US8;
|
||||
typedef signed int _US16;
|
||||
typedef signed long _US32;
|
||||
#else
|
||||
#error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// 64-bit Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_SUPPORT_64
|
||||
|
||||
//No 64-bit Support
|
||||
typedef _UU32 _U_UINT;
|
||||
typedef _US32 _U_SINT;
|
||||
|
||||
#else
|
||||
|
||||
//64-bit Support
|
||||
#if (UNITY_LONG_WIDTH == 32)
|
||||
typedef unsigned long long _UU64;
|
||||
typedef signed long long _US64;
|
||||
#elif (UNITY_LONG_WIDTH == 64)
|
||||
typedef unsigned long _UU64;
|
||||
typedef signed long _US64;
|
||||
#else
|
||||
#error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported)
|
||||
#endif
|
||||
typedef _UU64 _U_UINT;
|
||||
typedef _US64 _U_SINT;
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Pointer Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_POINTER_WIDTH
|
||||
#define UNITY_POINTER_WIDTH (32)
|
||||
#endif
|
||||
|
||||
#if (UNITY_POINTER_WIDTH == 32)
|
||||
typedef _UU32 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32
|
||||
#elif (UNITY_POINTER_WIDTH == 64)
|
||||
typedef _UU64 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64
|
||||
#elif (UNITY_POINTER_WIDTH == 16)
|
||||
typedef _UU16 _UP;
|
||||
#define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16
|
||||
#else
|
||||
#error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported)
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Float Support
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
|
||||
//No Floating Point Support
|
||||
#undef UNITY_FLOAT_PRECISION
|
||||
#undef UNITY_FLOAT_TYPE
|
||||
#undef UNITY_FLOAT_VERBOSE
|
||||
|
||||
#else
|
||||
|
||||
//Floating Point Support
|
||||
#ifndef UNITY_FLOAT_PRECISION
|
||||
#define UNITY_FLOAT_PRECISION (0.00001f)
|
||||
#endif
|
||||
#ifndef UNITY_FLOAT_TYPE
|
||||
#define UNITY_FLOAT_TYPE float
|
||||
#endif
|
||||
typedef UNITY_FLOAT_TYPE _UF;
|
||||
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Output Method
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_OUTPUT_CHAR
|
||||
//Default to using putchar, which is defined in stdio.h above
|
||||
#define UNITY_OUTPUT_CHAR(a) putchar(a)
|
||||
#else
|
||||
//If defined as something else, make sure we declare it here so it's ready for use
|
||||
extern int UNITY_OUTPUT_CHAR(int);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Footprint
|
||||
//-------------------------------------------------------
|
||||
|
||||
#ifndef UNITY_LINE_TYPE
|
||||
#define UNITY_LINE_TYPE unsigned short
|
||||
#endif
|
||||
|
||||
#ifndef UNITY_COUNTER_TYPE
|
||||
#define UNITY_COUNTER_TYPE unsigned short
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Internal Structs Needed
|
||||
//-------------------------------------------------------
|
||||
|
||||
typedef void (*UnityTestFunction)(void);
|
||||
|
||||
#define UNITY_DISPLAY_RANGE_INT (0x10)
|
||||
#define UNITY_DISPLAY_RANGE_UINT (0x20)
|
||||
#define UNITY_DISPLAY_RANGE_HEX (0x40)
|
||||
#define UNITY_DISPLAY_RANGE_AUTO (0x80)
|
||||
|
||||
typedef enum
|
||||
{
|
||||
UNITY_DISPLAY_STYLE_INT = 4 + UNITY_DISPLAY_RANGE_INT + UNITY_DISPLAY_RANGE_AUTO,
|
||||
UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT,
|
||||
UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT,
|
||||
UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT,
|
||||
#endif
|
||||
UNITY_DISPLAY_STYLE_UINT = 4 + UNITY_DISPLAY_RANGE_UINT + UNITY_DISPLAY_RANGE_AUTO,
|
||||
UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT,
|
||||
UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT,
|
||||
UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT,
|
||||
#endif
|
||||
UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX,
|
||||
UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX,
|
||||
UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX,
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX,
|
||||
#endif
|
||||
} UNITY_DISPLAY_STYLE_T;
|
||||
|
||||
struct _Unity
|
||||
{
|
||||
const char* TestFile;
|
||||
const char* CurrentTestName;
|
||||
_UU32 CurrentTestLineNumber;
|
||||
UNITY_COUNTER_TYPE NumberOfTests;
|
||||
UNITY_COUNTER_TYPE TestFailures;
|
||||
UNITY_COUNTER_TYPE TestIgnores;
|
||||
UNITY_COUNTER_TYPE CurrentTestFailed;
|
||||
UNITY_COUNTER_TYPE CurrentTestIgnored;
|
||||
jmp_buf AbortFrame;
|
||||
};
|
||||
|
||||
extern struct _Unity Unity;
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Suite Management
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityBegin(void);
|
||||
int UnityEnd(void);
|
||||
|
||||
void UnityConcludeTest(void);
|
||||
void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Output
|
||||
//-------------------------------------------------------
|
||||
|
||||
void UnityPrint(const char* string);
|
||||
void UnityPrintMask(const _U_UINT mask, const _U_UINT number);
|
||||
void UnityPrintNumberByStyle(const _U_SINT number, const UNITY_DISPLAY_STYLE_T style);
|
||||
void UnityPrintNumber(const _U_SINT number);
|
||||
void UnityPrintNumberUnsigned(const _U_UINT number);
|
||||
void UnityPrintNumberHex(const _U_UINT number, const char nibbles);
|
||||
|
||||
#ifdef UNITY_FLOAT_VERBOSE
|
||||
void UnityPrintFloat(const _UF number);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Assertion Fuctions
|
||||
//-------------------------------------------------------
|
||||
// Use the macros below this section instead of calling
|
||||
// these directly. The macros have a consistent naming
|
||||
// convention and will pull in file and line information
|
||||
// for you.
|
||||
|
||||
void UnityAssertEqualNumber(const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertEqualIntArray(const _U_SINT* expected,
|
||||
const _U_SINT* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityAssertBits(const _U_SINT mask,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualString(const char* expected,
|
||||
const char* actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualStringArray( const char** expected,
|
||||
const char** actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualMemory( const void* expected,
|
||||
const void* actual,
|
||||
const _UU32 length,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertNumbersWithin(const _U_SINT delta,
|
||||
const _U_SINT expected,
|
||||
const _U_SINT actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber,
|
||||
const UNITY_DISPLAY_STYLE_T style);
|
||||
|
||||
void UnityFail(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
void UnityIgnore(const char* message, const UNITY_LINE_TYPE line);
|
||||
|
||||
#ifndef UNITY_EXCLUDE_FLOAT
|
||||
void UnityAssertFloatsWithin(const _UF delta,
|
||||
const _UF expected,
|
||||
const _UF actual,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
|
||||
void UnityAssertEqualFloatArray(const _UF* expected,
|
||||
const _UF* actual,
|
||||
const _UU32 num_elements,
|
||||
const char* msg,
|
||||
const UNITY_LINE_TYPE lineNumber);
|
||||
#endif
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Basic Fail and Ignore
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)line);
|
||||
#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)line);
|
||||
|
||||
//-------------------------------------------------------
|
||||
// Test Asserts
|
||||
//-------------------------------------------------------
|
||||
|
||||
#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, message);}
|
||||
#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)line, message)
|
||||
#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)line, message)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((_U_SINT)(mask), (_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((_U_SINT)(delta), (_U_SINT)(expected), (_U_SINT)(actual), NULL, (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(_UP)(expected), (_U_SINT)(_UP)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_POINTER)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), 1, (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX8)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX16)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX32)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((const char**)(expected), (const char**)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((void*)(expected), (void*)(actual), (_UU32)(len), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
|
||||
#ifdef UNITY_SUPPORT_64
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((_U_SINT)(expected), (_U_SINT)(actual), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_INT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_UINT64)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((const _U_SINT*)(expected), (const _U_SINT*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line, UNITY_DISPLAY_STYLE_HEX64)
|
||||
#endif
|
||||
|
||||
#ifdef UNITY_EXCLUDE_FLOAT
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)line, "Unity Floating Point Disabled")
|
||||
#else
|
||||
#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((_UF)(delta), (_UF)(expected), (_UF)(actual), (message), (UNITY_LINE_TYPE)line)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((_UF)(expected) * (_UF)UNITY_FLOAT_PRECISION, (_UF)expected, (_UF)actual, (UNITY_LINE_TYPE)line, message)
|
||||
#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((_UF*)(expected), (_UF*)(actual), (_UU32)(num_elements), (message), (UNITY_LINE_TYPE)line)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
97
C/C3 Watch/Unity/unity_test_module.c
Normal file
97
C/C3 Watch/Unity/unity_test_module.c
Normal file
@@ -0,0 +1,97 @@
|
||||
#include "unity_test_module.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include "unity.h"
|
||||
|
||||
void (*unity_setUp_ptr)(void) = NULL;
|
||||
void (*unit_tearDown_ptr)(void) = NULL;
|
||||
|
||||
#ifdef UNITY_USE_MODULE_SETUP_TEARDOWN
|
||||
|
||||
void setUp()
|
||||
{
|
||||
if(unity_setUp_ptr != NULL) unity_setUp_ptr();
|
||||
}
|
||||
|
||||
void tearDown()
|
||||
{
|
||||
if(unit_tearDown_ptr != NULL) unit_tearDown_ptr();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) )
|
||||
{
|
||||
unity_setUp_ptr = setUp;
|
||||
unit_tearDown_ptr = tearDown;
|
||||
}
|
||||
|
||||
void UnityUnregisterSetupTearDown(void)
|
||||
{
|
||||
unity_setUp_ptr = NULL;
|
||||
unit_tearDown_ptr = NULL;
|
||||
}
|
||||
|
||||
UnityTestModule* UnityTestModuleFind(
|
||||
UnityTestModule* modules,
|
||||
size_t number_of_modules,
|
||||
char* wantedModule)
|
||||
{
|
||||
for(size_t i = 0; i < number_of_modules; i++) {
|
||||
if(strcmp(wantedModule, modules[i].name) == 0) {
|
||||
return &modules[i];
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void UnityTestModuleRunRequestedModules(
|
||||
int number_of_requested_modules,
|
||||
char* requested_modules_names[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules )
|
||||
{
|
||||
for(int i = 0; i < number_of_requested_modules; i++)
|
||||
{
|
||||
UnityTestModule* module = UnityTestModuleFind(allModules,
|
||||
number_of_modules, requested_modules_names[i]);
|
||||
|
||||
if(module != NULL)
|
||||
{
|
||||
module->run_tests();
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("Ignoring: could not find requested module: %s\n",
|
||||
requested_modules_names[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int UnityTestModuleRun(
|
||||
int argc,
|
||||
char * argv[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules)
|
||||
{
|
||||
UnityBegin();
|
||||
|
||||
bool moduleRequests = (argc > 1);
|
||||
|
||||
if(moduleRequests)
|
||||
{
|
||||
UnityTestModuleRunRequestedModules(argc-1, &argv[1],
|
||||
allModules, number_of_modules);
|
||||
}
|
||||
else
|
||||
{
|
||||
for(size_t i = 0; i < number_of_modules; i++)
|
||||
{
|
||||
allModules[i].run_tests();
|
||||
}
|
||||
}
|
||||
|
||||
return UnityEnd();
|
||||
}
|
||||
31
C/C3 Watch/Unity/unity_test_module.h
Normal file
31
C/C3 Watch/Unity/unity_test_module.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef UNITY_TEST_MODULE_H
|
||||
#define UNITY_TEST_MODULE_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct {
|
||||
char name[24];
|
||||
void(*run_tests)(void);
|
||||
} UnityTestModule;
|
||||
|
||||
void UnityRegisterSetupTearDown( void(*setUp)(void), void(*tearDown)(void) );
|
||||
void UnityUnregisterSetupTearDown(void);
|
||||
|
||||
UnityTestModule* UnityTestModuleFind(
|
||||
UnityTestModule* modules,
|
||||
size_t number_of_modules,
|
||||
char* wantedModule);
|
||||
|
||||
void UnityTestModuleRunRequestedModules(
|
||||
int number_of_requested_modules,
|
||||
char* requested_modules_names[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules );
|
||||
|
||||
int UnityTestModuleRun(
|
||||
int argc,
|
||||
char * argv[],
|
||||
UnityTestModule* allModules,
|
||||
size_t number_of_modules);
|
||||
|
||||
#endif
|
||||
BIN
C/C3 Watch/Watch-Registers-Assignment.docx
Normal file
BIN
C/C3 Watch/Watch-Registers-Assignment.docx
Normal file
Binary file not shown.
0
C/C3 Watch/build/.gitkeep
Normal file
0
C/C3 Watch/build/.gitkeep
Normal file
BIN
C/C3 Watch/build/main
Normal file
BIN
C/C3 Watch/build/main
Normal file
Binary file not shown.
BIN
C/C3 Watch/build/main_test
Normal file
BIN
C/C3 Watch/build/main_test
Normal file
Binary file not shown.
32
C/C3 Watch/product/main.c
Normal file
32
C/C3 Watch/product/main.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "watch.h"
|
||||
#include "watch_device_simulator.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
uint8_t hours = 11, minutes = 55, seconds = 42;
|
||||
|
||||
watch_set_time_hours(hours);
|
||||
watch_set_time_minutes(minutes);
|
||||
watch_set_time_seconds(seconds);
|
||||
|
||||
while (true)
|
||||
{
|
||||
watch_get_time(&hours, &minutes, &seconds);
|
||||
watch_device_simulator_print_time(hours, minutes, seconds);
|
||||
|
||||
uint8_t number_seconds_update = 10;
|
||||
watch_device_simulator_increase_time(number_seconds_update);
|
||||
sleep(number_seconds_update);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
303
C/C3 Watch/product/watch.c
Normal file
303
C/C3 Watch/product/watch.c
Normal file
@@ -0,0 +1,303 @@
|
||||
#include "watch.h"
|
||||
#include "watch_i2c.h"
|
||||
#include "watch_registers.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* C O N F I G */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int watch_config_reset()
|
||||
{
|
||||
uint8_t config = 0;
|
||||
if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_config_toggle_pause()
|
||||
{
|
||||
uint8_t config;
|
||||
if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
watch_registers_toggle_config_is_paused(&config);
|
||||
if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_config_set_time_format(time_format format)
|
||||
{
|
||||
uint8_t config;
|
||||
if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
watch_registers_set_config_time_format(&config, format);
|
||||
if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_config_set_time_update_interval(time_update_interval interval)
|
||||
{
|
||||
uint8_t config;
|
||||
if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
watch_registers_set_config_time_update_interval(&config, interval);
|
||||
if (watch_i2c_write_byte(ADDRESS_CONFIG, config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_config_get_settings(
|
||||
bool* is_paused, time_format* format,
|
||||
time_update_interval* interval)
|
||||
{
|
||||
uint8_t config;
|
||||
|
||||
if (is_paused == NULL || format == NULL || interval == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_CONFIG, &config) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
watch_registers_get_config_settings(config, is_paused, format, interval);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* T I M E */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int watch_set_time_hours(uint8_t hours)
|
||||
{
|
||||
uint8_t time_bits_low, time_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_set_time_minutes(uint8_t minutes)
|
||||
{
|
||||
uint8_t time_bits_low, time_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_set_time_seconds(uint8_t seconds)
|
||||
{
|
||||
uint8_t time_bits_low, time_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_LOW, time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_TIME_HIGH, time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_get_time(uint8_t* hours, uint8_t* minutes, uint8_t* seconds)
|
||||
{
|
||||
uint8_t time_bits_low, time_bits_high;
|
||||
|
||||
if (hours == NULL || minutes == NULL || seconds == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_LOW, &time_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_TIME_HIGH, &time_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_get_time(
|
||||
time_bits_low, time_bits_high, hours, minutes, seconds);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* D A T E */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int watch_set_date_year(uint16_t year)
|
||||
{
|
||||
uint8_t date_bits_low, date_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_set_date_year(&date_bits_low, &date_bits_low, year);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_set_date_month(uint8_t month)
|
||||
{
|
||||
uint8_t date_bits_low, date_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_set_date_month(&date_bits_low, &date_bits_low, month);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_set_date_day_of_month(uint8_t day_of_month)
|
||||
{
|
||||
uint8_t date_bits_low, date_bits_high;
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_set_date_day_of_month(
|
||||
&date_bits_low, &date_bits_low, day_of_month);
|
||||
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_LOW, date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_write_byte(ADDRESS_DATE_HIGH, date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_get_date(uint8_t* year, uint8_t* month, uint8_t* day_of_month)
|
||||
{
|
||||
uint8_t date_bits_low, date_bits_high;
|
||||
|
||||
if (year == NULL || month == NULL || day_of_month == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_LOW, &date_bits_low) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (watch_i2c_read_byte(ADDRESS_DATE_HIGH, &date_bits_high) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
watch_registers_get_date(
|
||||
date_bits_low, date_bits_low, year, month, day_of_month);
|
||||
|
||||
return 0;
|
||||
}
|
||||
31
C/C3 Watch/product/watch.h
Normal file
31
C/C3 Watch/product/watch.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef WATCH_H
|
||||
#define WATCH_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "watch_registers.h"
|
||||
|
||||
int watch_config_reset();
|
||||
int watch_config_toggle_pause();
|
||||
int watch_config_set_time_format(time_format format);
|
||||
int watch_config_set_time_update_interval(time_update_interval interval);
|
||||
int watch_config_get_settings(
|
||||
bool *is_paused,
|
||||
time_format* format,
|
||||
time_update_interval *interval);
|
||||
|
||||
int watch_set_time_hours(uint8_t hours);
|
||||
int watch_set_time_minutes(uint8_t minutes);
|
||||
int watch_set_time_seconds(uint8_t seconds);
|
||||
int watch_get_time(uint8_t* hours, uint8_t* minutes, uint8_t* seconds);
|
||||
|
||||
int watch_set_date_year(uint16_t year);
|
||||
int watch_set_date_month(uint8_t month);
|
||||
int watch_set_date_day_of_month(uint8_t day_of_month);
|
||||
int watch_get_date(uint8_t *year,
|
||||
uint8_t* month,
|
||||
uint8_t* day_of_month);
|
||||
|
||||
#endif
|
||||
107
C/C3 Watch/product/watch_device_simulator.c
Normal file
107
C/C3 Watch/product/watch_device_simulator.c
Normal file
@@ -0,0 +1,107 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "watch_device_simulator.h"
|
||||
#include "watch_i2c.h"
|
||||
#include "watch_registers.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
uint8_t register_values[5];
|
||||
|
||||
static int watch_device_simulator_address_to_array_index(
|
||||
uint8_t address, uint8_t* register_value_index)
|
||||
{
|
||||
if (register_value_index == NULL)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((address < ADDRESS_CONFIG) || (address > ADDRESS_DATE_HIGH))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*register_value_index = address - ADDRESS_CONFIG;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_device_simulator_write_byte(uint8_t address, uint8_t value)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
if (watch_device_simulator_address_to_array_index(address, &index) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
register_values[index] = value;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int watch_device_simulator_read_byte(uint8_t address, uint8_t* value)
|
||||
{
|
||||
uint8_t index = 0;
|
||||
if (watch_device_simulator_address_to_array_index(address, &index) != 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
*value = register_values[index];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void watch_device_simulator_add_one_second(
|
||||
uint8_t* hours, uint8_t* minutes, uint8_t* seconds)
|
||||
{
|
||||
*seconds += 1;
|
||||
|
||||
if (*seconds == 60)
|
||||
{
|
||||
*seconds = 0;
|
||||
*minutes += 1;
|
||||
if (*minutes == 60)
|
||||
{
|
||||
*minutes = 0;
|
||||
*hours += 1;
|
||||
if (*hours == 12)
|
||||
{
|
||||
*hours = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void watch_device_simulator_print_time(
|
||||
uint8_t hours, uint8_t minutes, uint8_t seconds)
|
||||
{
|
||||
printf("Time: %02d:%02d:%02d\n", hours, minutes, seconds);
|
||||
}
|
||||
|
||||
int watch_device_simulator_increase_time(uint8_t number_of_seconds)
|
||||
{
|
||||
uint8_t time_bits_low, time_bits_high = 0;
|
||||
watch_device_simulator_read_byte(ADDRESS_TIME_LOW, &time_bits_low);
|
||||
watch_device_simulator_read_byte(ADDRESS_TIME_HIGH, &time_bits_high);
|
||||
|
||||
uint8_t seconds = 0, minutes = 0, hours = 0;
|
||||
watch_registers_get_time(
|
||||
time_bits_low, time_bits_high, &hours, &minutes, &seconds);
|
||||
|
||||
for (uint8_t i = 0; i < number_of_seconds; i++)
|
||||
{
|
||||
watch_device_simulator_add_one_second(&hours, &minutes, &seconds);
|
||||
}
|
||||
|
||||
watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours);
|
||||
watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes);
|
||||
watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds);
|
||||
|
||||
watch_device_simulator_write_byte(ADDRESS_TIME_LOW, time_bits_low);
|
||||
watch_device_simulator_write_byte(ADDRESS_TIME_HIGH, time_bits_high);
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
C/C3 Watch/product/watch_device_simulator.h
Normal file
13
C/C3 Watch/product/watch_device_simulator.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef WATCH_DEVICE_SIMULATOR_H
|
||||
#define WATCH_DEVICE_SIMULATOR_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
int watch_device_simulator_write_byte(uint8_t address, uint8_t value);
|
||||
int watch_device_simulator_read_byte(uint8_t address, uint8_t* value);
|
||||
|
||||
int watch_device_simulator_increase_time(uint8_t number_of_seconds);
|
||||
void watch_device_simulator_print_time(
|
||||
uint8_t hours, uint8_t minutes, uint8_t seconds);
|
||||
|
||||
#endif
|
||||
15
C/C3 Watch/product/watch_i2c.c
Normal file
15
C/C3 Watch/product/watch_i2c.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "watch_i2c.h"
|
||||
#include "watch_device_simulator.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
int watch_i2c_write_byte(uint8_t address, uint8_t value)
|
||||
{
|
||||
return watch_device_simulator_write_byte(address, value);
|
||||
}
|
||||
|
||||
int watch_i2c_read_byte(uint8_t address, uint8_t* value)
|
||||
{
|
||||
return watch_device_simulator_read_byte(address, value);
|
||||
}
|
||||
11
C/C3 Watch/product/watch_i2c.h
Normal file
11
C/C3 Watch/product/watch_i2c.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef WATCH_I2C_H
|
||||
#define WATCH_I2C_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int watch_i2c_write_byte(uint8_t address, uint8_t value);
|
||||
int watch_i2c_read_byte(uint8_t address, uint8_t* value);
|
||||
|
||||
#endif
|
||||
66
C/C3 Watch/shared/watch_registers.c
Normal file
66
C/C3 Watch/shared/watch_registers.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#include "watch_registers.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
void watch_registers_toggle_config_is_paused(uint8_t* config)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_config_time_format(uint8_t* config, time_format format)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_config_time_update_interval(
|
||||
uint8_t* config, time_update_interval interval)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_get_config_settings(
|
||||
uint8_t config, bool* is_paused, time_format* format,
|
||||
time_update_interval* interval)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_time_hours(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t hours)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_time_minutes(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t minutes)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_time_seconds(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t seconds)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_get_time(
|
||||
uint8_t time_bits_low, uint8_t time_bits_high, uint8_t* hours,
|
||||
uint8_t* minutes, uint8_t* seconds)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_date_year(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t year)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_date_month(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t month)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_set_date_day_of_month(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high,
|
||||
uint8_t day_of_month)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_registers_get_date(
|
||||
uint8_t date_bits_low, uint8_t date_bits_high, uint8_t* year,
|
||||
uint8_t* month, uint8_t* day_of_month)
|
||||
{
|
||||
}
|
||||
189
C/C3 Watch/shared/watch_registers.h
Normal file
189
C/C3 Watch/shared/watch_registers.h
Normal file
@@ -0,0 +1,189 @@
|
||||
#ifndef WATCH_REGISTERS_H
|
||||
#define WATCH_REGISTERS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "watch_registers.h"
|
||||
|
||||
#define ADDRESS_CONFIG (0x20)
|
||||
#define ADDRESS_TIME_HIGH (0x21)
|
||||
#define ADDRESS_TIME_LOW (0x22)
|
||||
#define ADDRESS_DATE_HIGH (0x23)
|
||||
#define ADDRESS_DATE_LOW (0x24)
|
||||
|
||||
typedef enum {
|
||||
TIME_HOUR_MINUTE = 0,
|
||||
TIME_HOUR_MINUTE_SECOND = 1
|
||||
} time_format;
|
||||
|
||||
typedef enum {
|
||||
TIME_UPDATE_DISABLED = 0,
|
||||
TIME_EVERY_1_SECOND = 1,
|
||||
TIME_EVERY_30_SECONDS = 2,
|
||||
TIME_EVERY_MINUTE = 3
|
||||
} time_update_interval;
|
||||
|
||||
/*!
|
||||
* Update the configuration byte by toggling the pause bit.
|
||||
*
|
||||
* @param config: The address of the configuration byte that must be updated.
|
||||
*
|
||||
* @pre config may not be NULL.
|
||||
*/
|
||||
void watch_registers_toggle_config_is_paused(uint8_t* config);
|
||||
|
||||
/*!
|
||||
* Update the configuration byte by updating the time format.
|
||||
*
|
||||
* @param config: The address of the configuration byte that must be updated.
|
||||
* @param format: Time format setting.
|
||||
*
|
||||
* @pre config may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_config_time_format(
|
||||
uint8_t* config, time_format format);
|
||||
|
||||
/*!
|
||||
* Update the configuration byte by updating the time update interval.
|
||||
*
|
||||
* @param config: The address of the configuration byte that must be updated.
|
||||
* @param interval: Time update interval setting.
|
||||
*
|
||||
* @pre config may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_config_time_update_interval(
|
||||
uint8_t* config, time_update_interval interval);
|
||||
|
||||
/*!
|
||||
* Retrieve the configuration settings.
|
||||
*
|
||||
* @param config: The configuration byte.
|
||||
* @param is_paused: The address to which the is_paused setting will be written.
|
||||
* @param format: The address to which the time format will be written.
|
||||
* @param interval: The address to which the time update interval will be
|
||||
* written.
|
||||
*
|
||||
* @pre is_paused, format and interval may not be NULL.
|
||||
*/
|
||||
void watch_registers_get_config_settings(
|
||||
uint8_t config, bool* is_paused, time_format* format,
|
||||
time_update_interval* interval);
|
||||
|
||||
/*!
|
||||
* Update the time bytes by updating the hours bits.
|
||||
*
|
||||
* @param time_bits_low: The address to which the updated LSB part
|
||||
of the time will be written.
|
||||
* @param time_bits_high: The address to which the updated MSB part
|
||||
of the time will be written.
|
||||
* @param hours: The hour part of the time.
|
||||
*
|
||||
* @pre time_bits_low and time_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_time_hours(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t hours);
|
||||
|
||||
/*!
|
||||
* Update the time bytes by updating the minutes bits.
|
||||
*
|
||||
* @param time_bits_low: The address to which the updated LSB part
|
||||
of the time will be written.
|
||||
* @param time_bits_high: The address to which the updated MSB part
|
||||
of the time will be written.
|
||||
* @param minutes: The minute part of the time.
|
||||
*
|
||||
* @pre time_bits_low and time_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_time_minutes(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t minutes);
|
||||
|
||||
/*!
|
||||
* Update the time bytes by updating the seconds bits.
|
||||
*
|
||||
* @param time_bits_low: The address to which the updated LSB part
|
||||
of the time will be written.
|
||||
* @param time_bits_high: The address to which the updated MSB part
|
||||
of the time will be written.
|
||||
* @param seconds: The seconds part of the time.
|
||||
*
|
||||
* @pre time_bits_low and time_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_time_seconds(
|
||||
uint8_t* time_bits_low, uint8_t* time_bits_high, uint8_t seconds);
|
||||
|
||||
/*!
|
||||
* Retrieve the time fields.
|
||||
*
|
||||
* @param time_bits_low: The LSB part of the time.
|
||||
* @param time_bits_high: The MSB part of the time.
|
||||
* @param hours: The address to which the hours will be written.
|
||||
* @param minutes: The address to which the minutes will be written.
|
||||
* @param seconds: The address to which the seconds will be written.
|
||||
*
|
||||
* @pre hours, minutes and seconds may not be NULL.
|
||||
*/
|
||||
void watch_registers_get_time(
|
||||
uint8_t time_bits_low, uint8_t time_bits_high, uint8_t* hours,
|
||||
uint8_t* minutes, uint8_t* seconds);
|
||||
|
||||
/*!
|
||||
* Update the date bytes by updating the year bits.
|
||||
*
|
||||
* @param date_bits_low: The address to which the updated LSB part
|
||||
of the date will be written.
|
||||
* @param date_bits_high: The address to which the updated MSB part
|
||||
of the date will be written.
|
||||
* @param year: The year part of the time.
|
||||
*
|
||||
* @pre date_bits_low and date_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_date_year(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t year);
|
||||
|
||||
/*!
|
||||
* Update the date bytes by updating the month bits.
|
||||
*
|
||||
* @param date_bits_low: The address to which the updated LSB part
|
||||
of the date will be written.
|
||||
* @param date_bits_high: The address to which the updated MSB part
|
||||
of the date will be written.
|
||||
* @param month: The month part of the time.
|
||||
*
|
||||
* @pre date_bits_low and date_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_date_month(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high, uint8_t month);
|
||||
|
||||
/*!
|
||||
* Update the date bytes by updating the day_of_month bits.
|
||||
*
|
||||
* @param date_bits_low: The address to which the updated LSB part
|
||||
of the date will be written.
|
||||
* @param date_bits_high: The address to which the updated MSB part
|
||||
of the date will be written.
|
||||
* @param day_of_month: The day_of_month part of the time.
|
||||
*
|
||||
* @pre date_bits_low and date_bits_high may not be NULL.
|
||||
*/
|
||||
void watch_registers_set_date_day_of_month(
|
||||
uint8_t* date_bits_low, uint8_t* date_bits_high,
|
||||
uint8_t day_of_month);
|
||||
|
||||
/*!
|
||||
* Retrieve the date fields.
|
||||
*
|
||||
* @param date_bits_low: The LSB part of the date.
|
||||
* @param date_bits_high: The MSB part of the date.
|
||||
* @param year: The address to which the year will be written.
|
||||
* @param month: The address to which the month will be written.
|
||||
* @param day_of_month: The address to which the day_of_month will be written.
|
||||
*
|
||||
* @pre year, month and day_of_month may not be NULL.
|
||||
*/
|
||||
void watch_registers_get_date(
|
||||
uint8_t date_bits_low, uint8_t date_bits_high, uint8_t* year,
|
||||
uint8_t* month, uint8_t* day_of_month);
|
||||
|
||||
#endif
|
||||
20
C/C3 Watch/test/main.c
Normal file
20
C/C3 Watch/test/main.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include "unity_test_module.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
/* As an alternative for header files we can declare that
|
||||
* the following methos are available 'extern'ally.
|
||||
*/
|
||||
extern void run_watch_tests();
|
||||
extern void run_file_element_tests();
|
||||
|
||||
int main (int argc, char * argv[])
|
||||
{
|
||||
UnityTestModule allModules[] = { { "watch", run_watch_tests}
|
||||
};
|
||||
|
||||
size_t number_of_modules = sizeof(allModules)/sizeof(allModules[0]);
|
||||
|
||||
return UnityTestModuleRun(argc, argv, allModules, number_of_modules);
|
||||
}
|
||||
65
C/C3 Watch/test/watch_registers_test.c
Normal file
65
C/C3 Watch/test/watch_registers_test.c
Normal file
@@ -0,0 +1,65 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "unity_test_module.h"
|
||||
#include "watch_registers.h"
|
||||
|
||||
// leave resource_detector.h as last include!
|
||||
#include "resource_detector.h"
|
||||
|
||||
// I rather dislike keeping line numbers updated, so I made my own macro to
|
||||
// ditch the line number
|
||||
#define MY_RUN_TEST(func) RUN_TEST(func, 0)
|
||||
|
||||
void watch_setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void watch_tearDown(void)
|
||||
{
|
||||
// This is run after EACH test
|
||||
}
|
||||
|
||||
void test_setting_time_hours(void)
|
||||
{
|
||||
const uint8_t hours = 0xA5;
|
||||
uint8_t time_bits_high = 0xA5;
|
||||
uint8_t time_bits_low = 0x5A;
|
||||
|
||||
watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours);
|
||||
TEST_ASSERT_EQUAL_HEX8(0x55, time_bits_high);
|
||||
TEST_ASSERT_EQUAL_HEX8(0x5A, time_bits_low);
|
||||
}
|
||||
|
||||
void test_get_time()
|
||||
{
|
||||
const uint8_t hours = 11;
|
||||
const uint8_t minutes = 55;
|
||||
const uint8_t seconds = 42;
|
||||
uint8_t time_bits_low = 0;
|
||||
uint8_t time_bits_high = 0b00;
|
||||
|
||||
watch_registers_set_time_seconds(&time_bits_low, &time_bits_high, seconds);
|
||||
watch_registers_set_time_minutes(&time_bits_low, &time_bits_high, minutes);
|
||||
watch_registers_set_time_hours(&time_bits_low, &time_bits_high, hours);
|
||||
|
||||
uint8_t h;
|
||||
uint8_t m;
|
||||
uint8_t s;
|
||||
watch_registers_get_time(time_bits_low, time_bits_high, &h, &m, &s);
|
||||
TEST_ASSERT_EQUAL(hours, h);
|
||||
TEST_ASSERT_EQUAL(minutes, m);
|
||||
TEST_ASSERT_EQUAL(seconds, s);
|
||||
}
|
||||
|
||||
|
||||
void run_watch_tests()
|
||||
{
|
||||
UnityRegisterSetupTearDown( watch_setUp, watch_tearDown);
|
||||
|
||||
MY_RUN_TEST(test_setting_time_hours);
|
||||
MY_RUN_TEST(test_get_time);
|
||||
|
||||
UnityUnregisterSetupTearDown();
|
||||
}
|
||||
Reference in New Issue
Block a user