test_ui.c

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #include "CUnit/Basic.h"
00027 #include "test_shared.h"
00028 #include "test_ui.h"
00029 #include "../client/ui/ui_nodes.h"
00030 #include "../client/ui/ui_timer.h"
00031 
00036 static int UFO_InitSuiteUI (void)
00037 {
00038     TEST_Init();
00039     return 0;
00040 }
00041 
00046 static int UFO_CleanSuiteUI (void)
00047 {
00048     TEST_Shutdown();
00049     return 0;
00050 }
00051 
00056 static void testTimerDataStructure (void)
00057 {
00058     uiNode_t *dummyNode = (uiNode_t *) 0x1;
00059     timerCallback_t dummyCallback = (timerCallback_t) 0x1;
00060 
00061     uiTimer_t *a, *b, *c;
00062     a = UI_AllocTimer(dummyNode, 10, dummyCallback);
00063     b = UI_AllocTimer(dummyNode, 20, dummyCallback);
00064     c = UI_AllocTimer(dummyNode, 30, dummyCallback);
00065     CU_ASSERT(UI_GetFirstTimer() == NULL);
00066 
00067     UI_TimerStart(b);
00068     CU_ASSERT(UI_GetFirstTimer() == b);
00069 
00070     UI_TimerStart(a);
00071     CU_ASSERT(UI_GetFirstTimer() == a);
00072 
00073     UI_TimerStart(c);
00074     CU_ASSERT(UI_GetFirstTimer()->next->next == c);
00075 
00076     UI_TimerStop(a);
00077     UI_TimerStop(b);
00078     CU_ASSERT(a->owner != NULL);
00079     CU_ASSERT(UI_GetFirstTimer() == c);
00080     CU_ASSERT(UI_GetFirstTimer()->next == NULL);
00081 
00082     UI_TimerStart(a);
00083     CU_ASSERT(UI_GetFirstTimer() == a);
00084     CU_ASSERT(UI_GetFirstTimer()->next == c);
00085 
00086     UI_PrivateInsertTimerInActiveList(a->next, b);
00087     CU_ASSERT(UI_GetFirstTimer() == a);
00088     CU_ASSERT(UI_GetFirstTimer()->next == b);
00089     CU_ASSERT(UI_GetFirstTimer()->next->next == c);
00090 
00091     UI_TimerRelease(b);
00092     CU_ASSERT(UI_GetFirstTimer() == a);
00093     CU_ASSERT(UI_GetFirstTimer()->next == c);
00094 
00095     UI_TimerRelease(a);
00096     CU_ASSERT(UI_GetFirstTimer() == c);
00097 
00098     UI_TimerRelease(c);
00099     CU_ASSERT(UI_GetFirstTimer() == NULL);
00100     CU_ASSERT(c->owner == NULL);
00101 }
00102 
00103 int UFO_AddUITests (void)
00104 {
00105     /* add a suite to the registry */
00106     CU_pSuite UISuite = CU_add_suite("UITests", UFO_InitSuiteUI, UFO_CleanSuiteUI);
00107 
00108     if (UISuite == NULL)
00109         return CU_get_error();
00110 
00111     /* add the tests to the suite */
00112     if (CU_ADD_TEST(UISuite, testTimerDataStructure) == NULL)
00113         return CU_get_error();
00114 
00115     return CUE_SUCCESS;
00116 }

Generated by  doxygen 1.6.2