Removed tests
This commit is contained in:
@@ -1,34 +1,39 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#include "../include/ci2.h"
|
||||
#include <stdlib.h> // malloc calloc free
|
||||
const struct CI2_Exception oom = { ENOMEM, "Out of memory!" };
|
||||
|
||||
void *ci2_alloc(size_t nbytes, const char *file, int line){
|
||||
void *ci2_alloc(
|
||||
size_t nbytes,
|
||||
const char *file,
|
||||
int line)
|
||||
{
|
||||
void *ptr;
|
||||
ci2_rt_assert(nbytes > 0);
|
||||
ptr = malloc(nbytes);
|
||||
if (ptr == NULL){
|
||||
if (ptr == NULL)
|
||||
{
|
||||
if (file == NULL)
|
||||
CI2_RAISE(oom);
|
||||
else
|
||||
@@ -36,12 +41,18 @@ void *ci2_alloc(size_t nbytes, const char *file, int line){
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
void *ci2_calloc(size_t count, size_t nbytes, const char *file, int line){
|
||||
void *ci2_calloc(
|
||||
size_t count,
|
||||
size_t nbytes,
|
||||
const char *file,
|
||||
int line)
|
||||
{
|
||||
void *ptr;
|
||||
ci2_rt_assert(count > 0);
|
||||
ci2_rt_assert(nbytes > 0);
|
||||
ptr = calloc(count, nbytes);
|
||||
if (ptr == NULL){
|
||||
if (ptr == NULL)
|
||||
{
|
||||
if (file == NULL)
|
||||
CI2_RAISE(oom);
|
||||
else
|
||||
@@ -49,7 +60,11 @@ void *ci2_calloc(size_t count, size_t nbytes, const char *file, int line){
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
void ci2_free(void *ptr, const char *file, int line){
|
||||
void ci2_free(
|
||||
void *ptr,
|
||||
const char *file,
|
||||
int line)
|
||||
{
|
||||
(void) file;
|
||||
(void) line;
|
||||
|
||||
@@ -57,7 +72,12 @@ void ci2_free(void *ptr, const char *file, int line){
|
||||
free(ptr);
|
||||
|
||||
}
|
||||
void *ci2_resize(void *ptr, size_t nbytes, const char *file, int line) {
|
||||
void *ci2_resize(
|
||||
void *ptr,
|
||||
size_t nbytes,
|
||||
const char *file,
|
||||
int line)
|
||||
{
|
||||
// ci2_rt_assert(ptr); // ? Maybe
|
||||
// ci2_rt_assert(nbytes > 0);// ? Maybe
|
||||
void *tmp = realloc(ptr, nbytes);
|
||||
@@ -67,7 +87,7 @@ void *ci2_resize(void *ptr, size_t nbytes, const char *file, int line) {
|
||||
else
|
||||
ci2_raise_exception(&oom, file, line, CURRENT_FUNC);
|
||||
}
|
||||
|
||||
|
||||
ptr = tmp;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -25,17 +25,25 @@ SOFTWARE.
|
||||
struct CI2_Exception_Frame *ci2_exception_stack = NULL;
|
||||
const struct CI2_Exception runtime_assertion_failed = { EINVAL, "CI2 Runtime Assertion Failed" };
|
||||
|
||||
void ci2_rt_assert(int e){
|
||||
if(!e){
|
||||
void ci2_rt_assert(int e)
|
||||
{
|
||||
if(!e)
|
||||
{
|
||||
CI2_RAISE(runtime_assertion_failed);
|
||||
}
|
||||
}
|
||||
|
||||
void ci2_raise_exception(const struct CI2_Exception *e, const char *file,int line, const char *func){
|
||||
void ci2_raise_exception(
|
||||
const struct CI2_Exception *e,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func)
|
||||
{
|
||||
|
||||
struct CI2_Exception_Frame *p = ci2_exception_stack;
|
||||
CI2_ASSERT(e != NULL);
|
||||
if (p == NULL) {
|
||||
if (p == NULL)
|
||||
{
|
||||
fprintf(stderr, "CI2 Uncaught Exception");
|
||||
if(e->num > 0)
|
||||
fprintf(stderr," %d ",e->num);
|
||||
@@ -50,6 +58,7 @@ void ci2_raise_exception(const struct CI2_Exception *e, const char *file,int lin
|
||||
fflush(stderr);
|
||||
CI2_DEBUG_BREAK();
|
||||
}
|
||||
|
||||
p->exception = e;
|
||||
p->file = file;
|
||||
p->line = line;
|
||||
|
||||
@@ -35,11 +35,16 @@ struct CI2_Window {
|
||||
Atom wm_delete_window;
|
||||
};
|
||||
|
||||
ci2_bool ci2_init(void) {
|
||||
ci2_bool ci2_init(void)
|
||||
{
|
||||
return ci2_true; // Nothing global needed for X11
|
||||
}
|
||||
|
||||
CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height) {
|
||||
CI2_Window* ci2_create_window(
|
||||
const ci2_sys_char* title,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
Display* display = XOpenDisplay(NULL);
|
||||
if (!display) return NULL;
|
||||
|
||||
@@ -59,27 +64,33 @@ CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height)
|
||||
|
||||
|
||||
CI2_Window* window = malloc(sizeof(CI2_Window));
|
||||
if (!window) {
|
||||
if (!window)
|
||||
{
|
||||
XDestroyWindow(display, win);
|
||||
XCloseDisplay(display);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
window->display = display;
|
||||
window->wm_delete_window = wm_delete_window;
|
||||
window->handle.should_close = ci2_false;
|
||||
window->handle.fd = win;
|
||||
|
||||
return window;
|
||||
}
|
||||
|
||||
ci2_bool ci2_poll_events(CI2_Window* window) {
|
||||
ci2_bool ci2_poll_events(CI2_Window* window)
|
||||
{
|
||||
if (!window) return ci2_false;
|
||||
|
||||
while (XPending(window->display)) {
|
||||
while (XPending(window->display))
|
||||
{
|
||||
XEvent event;
|
||||
XNextEvent(window->display, &event);
|
||||
|
||||
if (event.type == ClientMessage &&
|
||||
(Atom)event.xclient.data.l[0] == window->wm_delete_window) {
|
||||
(Atom)event.xclient.data.l[0] == window->wm_delete_window)
|
||||
{
|
||||
window->handle.should_close = ci2_true;
|
||||
}
|
||||
}
|
||||
@@ -87,7 +98,8 @@ ci2_bool ci2_poll_events(CI2_Window* window) {
|
||||
return !window->handle.should_close;
|
||||
}
|
||||
|
||||
void ci2_destroy_window(CI2_Window* window) {
|
||||
void ci2_destroy_window(CI2_Window* window)
|
||||
{
|
||||
if (!window) return;
|
||||
|
||||
XDestroyWindow(window->display, window->handle.fd);
|
||||
@@ -95,11 +107,13 @@ void ci2_destroy_window(CI2_Window* window) {
|
||||
free(window);
|
||||
}
|
||||
|
||||
void ci2_shutdown(void) {
|
||||
void ci2_shutdown(void)
|
||||
{
|
||||
// Nothing global needed
|
||||
}
|
||||
|
||||
ci2_bool ci2_main(int argc, ci2_sys_char *argv[]){
|
||||
ci2_bool ci2_main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -25,8 +25,10 @@ SOFTWARE.
|
||||
DWORD ci2_exception_index = -1;
|
||||
const struct CI2_Exception runtime_assertion_failed = { EINVAL, "CI2 Runtime Assertion Failed" };
|
||||
|
||||
void ci2_rt_assert(int e){
|
||||
if(!e){
|
||||
void ci2_rt_assert(int e)
|
||||
{
|
||||
if(!e)
|
||||
{
|
||||
CI2_RAISE(runtime_assertion_failed);
|
||||
}
|
||||
}
|
||||
@@ -37,15 +39,22 @@ _CRTIMP void __cdecl _assert(void *, void *, unsigned);
|
||||
#define ci2_rt_assert(e) ((e) || (_assert(#e, __FILE__, __LINE__), 0))
|
||||
#endif
|
||||
|
||||
void ci2_raise_exception(const struct CI2_Exception *e, const char *file, int line, const char *func){
|
||||
void ci2_raise_exception(
|
||||
const struct CI2_Exception *e,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func)
|
||||
{
|
||||
struct CI2_Exception_Frame *p;
|
||||
|
||||
if (ci2_exception_index == TLS_OUT_OF_INDEXES)
|
||||
ci2_exception_init();
|
||||
p = TlsGetValue(ci2_exception_index);
|
||||
CI2_ASSERT(e != NULL);
|
||||
if (p == NULL) {
|
||||
if (p == NULL) {
|
||||
if (p == NULL)
|
||||
{
|
||||
if (p == NULL)
|
||||
{
|
||||
fprintf(stderr, "CI2 Uncaught Exception");
|
||||
if(e->num > 0)
|
||||
fprintf(stderr," %d ",e->num);
|
||||
@@ -71,7 +80,8 @@ void ci2_raise_exception(const struct CI2_Exception *e, const char *file, int li
|
||||
longjmp(p->env, CI2_EXCEPT_STATE_RAISED);
|
||||
}
|
||||
|
||||
void ci2_exception_init(void) {
|
||||
void ci2_exception_init(void)
|
||||
{
|
||||
BOOL cond;
|
||||
ci2_exception_index = TlsAlloc();
|
||||
CI2_ASSERT(ci2_exception_index != TLS_OUT_OF_INDEXES);
|
||||
@@ -79,14 +89,16 @@ void ci2_exception_init(void) {
|
||||
CI2_ASSERT(cond == TRUE);
|
||||
}
|
||||
|
||||
void ci2_exception_push(struct CI2_Exception_Frame *fp) {
|
||||
void ci2_exception_push(struct CI2_Exception_Frame *fp)
|
||||
{
|
||||
BOOL cond;
|
||||
fp->prev = TlsGetValue(ci2_exception_index);
|
||||
cond = TlsSetValue(ci2_exception_index, fp);
|
||||
CI2_ASSERT(cond == TRUE);
|
||||
}
|
||||
|
||||
void ci2_exception_pop(void) {
|
||||
void ci2_exception_pop(void)
|
||||
{
|
||||
BOOL cond;
|
||||
struct CI2_Exception_Frame *tos = TlsGetValue(ci2_exception_index);
|
||||
cond = TlsSetValue(ci2_exception_index, tos->prev);
|
||||
|
||||
@@ -32,16 +32,22 @@ struct CI2_Window {
|
||||
// Forward declaration of WndProc
|
||||
static LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
ci2_bool ci2_init(void) {
|
||||
ci2_bool ci2_init(void)
|
||||
{
|
||||
// Nothing to do for Win32
|
||||
return true;
|
||||
}
|
||||
|
||||
CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height) {
|
||||
CI2_Window* ci2_create_window(
|
||||
const ci2_sys_char* title,
|
||||
int width,
|
||||
int height)
|
||||
{
|
||||
static ci2_bool class_registered = false;
|
||||
static ci2_sys_char *ci2_window_class = L"Win32 CI2 Window Class";
|
||||
|
||||
if (!class_registered) {
|
||||
if (!class_registered)
|
||||
{
|
||||
WNDCLASS wc = {0};
|
||||
wc.lpfnWndProc = window_proc;
|
||||
wc.hInstance = GetModuleHandle(NULL);
|
||||
@@ -65,7 +71,8 @@ CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height)
|
||||
if (!hwnd) return NULL;
|
||||
|
||||
CI2_Window* window = malloc(sizeof(CI2_Window));
|
||||
if (!window) {
|
||||
if (!window)
|
||||
{
|
||||
DestroyWindow(hwnd);
|
||||
return NULL;
|
||||
}
|
||||
@@ -81,35 +88,47 @@ CI2_Window* ci2_create_window(const ci2_sys_char* title, int width, int height)
|
||||
return window;
|
||||
}
|
||||
|
||||
ci2_bool ci2_poll_events(CI2_Window* window) {
|
||||
ci2_bool ci2_poll_events(CI2_Window* window)
|
||||
{
|
||||
MSG msg;
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
return !window->handle.should_close;
|
||||
}
|
||||
|
||||
void ci2_destroy_window(CI2_Window* window) {
|
||||
void ci2_destroy_window(CI2_Window* window)
|
||||
{
|
||||
if (!window) return;
|
||||
|
||||
DestroyWindow(window->handle.fd);
|
||||
free(window);
|
||||
}
|
||||
|
||||
void ci2_shutdown(void) {
|
||||
void ci2_shutdown(void)
|
||||
{
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
ci2_bool ci2_main(int argc, ci2_sys_char *argv[]){
|
||||
ci2_bool ci2_main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK window_proc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
||||
static LRESULT CALLBACK window_proc(
|
||||
HWND hwnd,
|
||||
UINT uMsg,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam)
|
||||
{
|
||||
CI2_Window* window = (CI2_Window*)GetWindowLongPtr(hwnd, GWLP_USERDATA);
|
||||
|
||||
switch (uMsg) {
|
||||
switch (uMsg)
|
||||
{
|
||||
case WM_CLOSE:
|
||||
if (window) window->handle.should_close = ci2_true;
|
||||
return 0;
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#define DEBUG
|
||||
#define GUI_DEBUG_CLOSE
|
||||
|
||||
#include "../include/ci2.h"
|
||||
#include <stdlib.h>
|
||||
#include <limits.h> /* INT_MAX, CHAR_BIT — C standard */
|
||||
#include <float.h> /* FLT_MANT_DIG — C standard */
|
||||
#include <stdint.h> /* integer types — C standard */
|
||||
|
||||
|
||||
static int ci2_static_assertions(void){
|
||||
|
||||
/* Fundamental type sizes that almost all C code silently assumes. */
|
||||
CI2_STATIC_ASSERT(CHAR_BIT == 8);
|
||||
CI2_STATIC_ASSERT(sizeof(char) == 1);
|
||||
CI2_STATIC_ASSERT(sizeof(short) == 2);
|
||||
CI2_STATIC_ASSERT(sizeof(int) == 4);
|
||||
CI2_STATIC_ASSERT(sizeof(float) == 4);
|
||||
CI2_STATIC_ASSERT(sizeof(double) == 8);
|
||||
|
||||
/* Pointer and size_t width — catches ILP64 oddities. */
|
||||
CI2_STATIC_ASSERT(sizeof(void *) == sizeof(size_t));
|
||||
|
||||
/* Fixed-width types from <stdint.h> */
|
||||
CI2_STATIC_ASSERT(sizeof(int8_t) == 1);
|
||||
CI2_STATIC_ASSERT(sizeof(int16_t) == 2);
|
||||
CI2_STATIC_ASSERT(sizeof(int32_t) == 4);
|
||||
CI2_STATIC_ASSERT(sizeof(int64_t) == 8);
|
||||
|
||||
CI2_STATIC_ASSERT(sizeof(uint8_t) == 1);
|
||||
CI2_STATIC_ASSERT(sizeof(uint16_t) == 2);
|
||||
CI2_STATIC_ASSERT(sizeof(uint32_t) == 4);
|
||||
CI2_STATIC_ASSERT(sizeof(uint64_t) == 8);
|
||||
|
||||
/* IEEE-754 single precision: 24 significand bits. */
|
||||
CI2_STATIC_ASSERT(FLT_MANT_DIG == 24);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CI2_WINDOWS
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void) nShowCmd;
|
||||
if (!ci2_init()) {
|
||||
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static ci2_sys_char *ci2_window_title = L"Win32 CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) {
|
||||
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
|
||||
ci2_shutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 4) Main loop: run until ci2_poll_events reports the window should close.
|
||||
// This loop is friendly to rendering or other per-frame work.
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Per-frame update/render would go here.
|
||||
// Example: simple sleep to avoid busy-looping; adjust to suit your app's timing.
|
||||
result = ci2_static_assertions();
|
||||
Sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 5) Destroy window and shutdown ci2.
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
#else /* non-Windows (Linux, macOS, etc.) */
|
||||
#include <unistd.h>
|
||||
int main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
if (!ci2_init()) return 1;
|
||||
|
||||
static ci2_sys_char *ci2_window_title = "Linux CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) return 1;
|
||||
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Your rendering / game loop goes here
|
||||
result = ci2_static_assertions();
|
||||
sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,150 +0,0 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#define DEBUG
|
||||
#define GUI_DEBUG_CLOSE
|
||||
|
||||
#include "../include/ci2.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
static int test_assert_failing(void){
|
||||
#ifdef CI2_ASSERT_CRASH
|
||||
printf("ASSERT_MSG — Deliberate Failure (expect a debug break)");
|
||||
printf(" Triggering ASSERT_MSG(0, ...) now...\n");
|
||||
fflush(stdout);
|
||||
|
||||
CI2_ASSERT_MSG(0, "This failure is intentional — testing the message path");
|
||||
|
||||
printf(" [FAIL] Execution continued past a failing ASSERT_MSG!\n");
|
||||
#else
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef CI2_WINDOWS
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void) nShowCmd;
|
||||
if (!ci2_init()) {
|
||||
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static ci2_sys_char *ci2_window_title = L"Win32 CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) {
|
||||
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
|
||||
ci2_shutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 4) Main loop: run until ci2_poll_events reports the window should close.
|
||||
// This loop is friendly to rendering or other per-frame work.
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Per-frame update/render would go here.
|
||||
// Example: simple sleep to avoid busy-looping; adjust to suit your app's timing.
|
||||
|
||||
CI2_ASSERT(ci2_true);
|
||||
CI2_ASSERT(1);
|
||||
CI2_ASSERT(1 == 1);
|
||||
|
||||
/* Pointer non-null */
|
||||
const char *str = "hello";
|
||||
CI2_ASSERT(str != NULL);
|
||||
|
||||
/* Arithmetic */
|
||||
int x = 42;
|
||||
CI2_ASSERT(x > 0);
|
||||
CI2_ASSERT(x * 2 == 84);
|
||||
|
||||
/* CI2_ASSERT_MSG variants */
|
||||
CI2_ASSERT_MSG(x == 42, "x must be 42");
|
||||
CI2_ASSERT_MSG(sizeof(int) == 4, "int must be 4 bytes on this platform");
|
||||
|
||||
/* Boolean */
|
||||
bool flag = true;
|
||||
CI2_ASSERT(flag);
|
||||
result = test_assert_failing();
|
||||
Sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 5) Destroy window and shutdown ci2.
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
#else /* non-Windows (Linux, macOS, etc.) */
|
||||
#include <unistd.h>
|
||||
int main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
if (!ci2_init()) return 1;
|
||||
|
||||
static ci2_sys_char *ci2_window_title = "Linux CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) return 1;
|
||||
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Your rendering / game loop goes here
|
||||
CI2_ASSERT(ci2_true);
|
||||
|
||||
CI2_ASSERT(1);
|
||||
CI2_ASSERT(1 == 1);
|
||||
|
||||
/* Pointer non-null */
|
||||
const char *str = "hello";
|
||||
CI2_ASSERT(str != NULL);
|
||||
|
||||
/* Arithmetic */
|
||||
int x = 42;
|
||||
CI2_ASSERT(x > 0);
|
||||
CI2_ASSERT(x * 2 == 84);
|
||||
|
||||
/* CI2_ASSERT_MSG variants */
|
||||
CI2_ASSERT_MSG(x == 42, "x must be 42");
|
||||
CI2_ASSERT_MSG(sizeof(int) == 4, "int must be 4 bytes on this platform");
|
||||
|
||||
/* Boolean */
|
||||
bool flag = true;
|
||||
CI2_ASSERT(flag);
|
||||
result = test_assert_failing();
|
||||
sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,137 +0,0 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#define DEBUG
|
||||
#define GUI_DEBUG_CLOSE
|
||||
|
||||
#include "../include/ci2.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static int test_error_num;
|
||||
const struct CI2_Exception e = { EOWNERDEAD , "Owner died"};
|
||||
|
||||
static void test_exception(){
|
||||
test_error_num = EOWNERDEAD; // Oops better revive them.
|
||||
CI2_RAISE(e);
|
||||
}
|
||||
static int test_caught_exception(){
|
||||
CI2_TRY {
|
||||
printf("Trying to catch a failure.\n");
|
||||
// Oops
|
||||
test_exception();
|
||||
}
|
||||
CI2_EXCEPT(e) {
|
||||
/* handle error failure gracefully */
|
||||
fprintf(stderr, "Caught: %d: %s.\n", e.num, e.msg);
|
||||
test_error_num = 0;
|
||||
}
|
||||
CI2_FINALLY {
|
||||
/* Runs no matter what */
|
||||
printf("Hope we caught something.\n");
|
||||
}
|
||||
CI2_END_TRY;
|
||||
|
||||
return test_error_num;
|
||||
}
|
||||
static int test_uncaught_exception(void){
|
||||
#ifdef CI2_EXCEPTION_CRASH
|
||||
printf("CI2_MSG — Deliberate Failure (expect a debug break)\n");
|
||||
printf(" Triggering ci2_raise_exception() now...\n");
|
||||
fflush(stdout);
|
||||
|
||||
struct CI2_Exception u = { EFAULT, "Deliberate uncaught exception test."};
|
||||
CI2_RAISE(u);
|
||||
printf(" [FAIL] Execution continued past a failing ASSERT_MSG!\n");
|
||||
return EXIT_SUCCESS; // Shouldn't but still.
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CI2_WINDOWS
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void) nShowCmd;
|
||||
if (!ci2_init()) {
|
||||
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static ci2_sys_char *ci2_window_title = L"Win32 CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) {
|
||||
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
|
||||
ci2_shutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 4) Main loop: run until ci2_poll_events reports the window should close.
|
||||
// This loop is friendly to rendering or other per-frame work.
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Per-frame update/render would go here.
|
||||
// Example: simple sleep to avoid busy-looping; adjust to suit your app's timing.
|
||||
|
||||
result = test_uncaught_exception();
|
||||
result = test_caught_exception();
|
||||
Sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 5) Destroy window and shutdown ci2.
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
#else /* non-Windows (Linux, macOS, etc.) */
|
||||
#include <unistd.h>
|
||||
int main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
if (!ci2_init()) return 1;
|
||||
|
||||
static ci2_sys_char *ci2_window_title = "Linux CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) return 1;
|
||||
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Your rendering / game loop goes here
|
||||
|
||||
result = test_uncaught_exception();
|
||||
result = test_caught_exception();
|
||||
sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,141 +0,0 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#define DEBUG
|
||||
#define GUI_DEBUG_CLOSE
|
||||
|
||||
#include "../include/ci2.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static int test_caught_exception(){
|
||||
size_t nbytes = CI2_GB(1024);
|
||||
void *buf = NULL;
|
||||
const char *str = "Hello World";
|
||||
buf = CI2_CALLOC(1,strlen(str+1)); /* You have no enable asan options. */
|
||||
strncpy(buf,str,strlen(str));
|
||||
|
||||
char *opts = "ASAN_OPTIONS=allocator_may_fail=1";
|
||||
|
||||
printf("Attempting oom re-allocation of %ld at %p\n", nbytes, buf);
|
||||
printf("Adding %s to env....%d\n",opts, putenv(opts));
|
||||
|
||||
CI2_TRY {
|
||||
printf("Trying something dumb.\n");
|
||||
CI2_RESIZE(buf, nbytes);
|
||||
}
|
||||
CI2_EXCEPT(oom) {
|
||||
/* handle memory failure gracefully */
|
||||
printf("Caught: %d: %s\n", oom.num, oom.msg);
|
||||
return EXIT_SUCCESS; /* requested behavior */
|
||||
}
|
||||
CI2_FINALLY {
|
||||
/* cleanup if needed, runs always */
|
||||
printf("Have to free allocation of %ld at %p\n",strlen(buf), buf );
|
||||
if (buf) free(buf);
|
||||
}
|
||||
CI2_END_TRY;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static int test_uncaught_exception(void){
|
||||
#ifdef CI2_EXCEPTION_CRASH
|
||||
printf("CI2_MSG — Deliberate Failure (expect a debug break)\n");
|
||||
printf(" Triggering ci2_raise_exception() now...\n");
|
||||
fflush(stdout);
|
||||
|
||||
struct CI2_Exception u = { EFAULT, "Deliberate uncaught exception test."};
|
||||
CI2_RAISE(u);
|
||||
printf(" [FAIL] Execution continued past a failing ASSERT_MSG!\n");
|
||||
return EXIT_SUCCESS; // Shouldn't but still.
|
||||
#endif
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
#ifdef CI2_WINDOWS
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void) nShowCmd;
|
||||
if (!ci2_init()) {
|
||||
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static ci2_sys_char *ci2_window_title = L"Win32 CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) {
|
||||
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
|
||||
ci2_shutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 4) Main loop: run until ci2_poll_events reports the window should close.
|
||||
// This loop is friendly to rendering or other per-frame work.
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Per-frame update/render would go here.
|
||||
// Example: simple sleep to avoid busy-looping; adjust to suit your app's timing.
|
||||
|
||||
result = test_uncaught_exception();
|
||||
result = test_caught_exception();
|
||||
Sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 5) Destroy window and shutdown ci2.
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
|
||||
return result;
|
||||
}
|
||||
#else /* non-Windows (Linux, macOS, etc.) */
|
||||
#include <unistd.h>
|
||||
int main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
if (!ci2_init()) return 1;
|
||||
|
||||
static ci2_sys_char *ci2_window_title = "Linux CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) return 1;
|
||||
|
||||
int result = -1;
|
||||
while (ci2_poll_events(window)) {
|
||||
// Your rendering / game loop goes here
|
||||
|
||||
result = test_uncaught_exception();
|
||||
result = test_caught_exception();
|
||||
sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
@@ -1,88 +0,0 @@
|
||||
/* - | Copyright | --------------------------------------------------------------
|
||||
Copyright (c) 2026 Randy Jordan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
* --------------------------------------------------------------------------*/
|
||||
#define DEBUG
|
||||
#define GUI_DEBUG_CLOSE
|
||||
#include "../include/ci2.h"
|
||||
|
||||
#ifdef CI2_WINDOWS
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
||||
{
|
||||
(void)hInstance;
|
||||
(void)hPrevInstance;
|
||||
(void)lpCmdLine;
|
||||
(void) nShowCmd;
|
||||
if (!ci2_init()) {
|
||||
MessageBoxA(NULL, "ci2_init failed", "Error", MB_OK | MB_ICONERROR);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
static ci2_sys_char *ci2_window_title = L"Win32 CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) {
|
||||
MessageBoxA(NULL, "ci2_create_window failed", "Error", MB_OK | MB_ICONERROR);
|
||||
ci2_shutdown();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
// 4) Main loop: run until ci2_poll_events reports the window should close.
|
||||
// This loop is friendly to rendering or other per-frame work.
|
||||
|
||||
while (ci2_poll_events(window)) {
|
||||
// Per-frame update/render would go here.
|
||||
// Example: simple sleep to avoid busy-looping; adjust to suit your app's timing.
|
||||
Sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
// 5) Destroy window and shutdown ci2.
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* non-Windows (Linux, macOS, etc.) */
|
||||
#include <unistd.h>
|
||||
int main(int argc, ci2_sys_char *argv[])
|
||||
{
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
if (!ci2_init()) return 1;
|
||||
|
||||
static ci2_sys_char *ci2_window_title = "Linux CI2 Window Title";
|
||||
CI2_Window* window = ci2_create_window(ci2_window_title, 800, 600);
|
||||
if (!window) return 1;
|
||||
|
||||
while (ci2_poll_events(window)) {
|
||||
// Your rendering / game loop goes here
|
||||
sleep(1);
|
||||
#ifdef GUI_DEBUG_CLOSE
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
ci2_destroy_window(window);
|
||||
ci2_shutdown();
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user