OSDN Git Service

add test cases for cssrendering_box_t and cssrendering_coordinate_t.
authorornse01 <ornse01@users.sourceforge.jp>
Mon, 6 May 2013 10:03:41 +0000 (10:03 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Mon, 6 May 2013 10:03:41 +0000 (10:03 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@556 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/css/test_css.h [new file with mode: 0644]
src/css/test_cssrendering_box.c [new file with mode: 0644]
src/css/test_cssrendering_coordinate.c [new file with mode: 0644]

diff --git a/src/css/test_css.h b/src/css/test_css.h
new file mode 100644 (file)
index 0000000..5534d9c
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * test_css.h
+ *
+ * Copyright (c) 2013 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+#include       <basic.h>
+#include    <unittest_driver.h>
+
+#ifndef __TEST_CSS_H__
+#define __TEST_CSS_H__
+
+IMPORT VOID test_cssrendering_box_main(unittest_driver_t *driver);
+IMPORT VOID test_cssrendering_coordinate_main(unittest_driver_t *driver);
+
+#endif
diff --git a/src/css/test_cssrendering_box.c b/src/css/test_cssrendering_box.c
new file mode 100644 (file)
index 0000000..7becd99
--- /dev/null
@@ -0,0 +1,121 @@
+/*
+ * test_cssrendering_box.c
+ *
+ * Copyright (c) 2013 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+#include "test_css.h"
+
+#include "cssrendering_box.h"
+
+#include       <basic.h>
+#include       <bstdio.h>
+#include       <bstdlib.h>
+#include       <bstring.h>
+
+#include    <unittest_driver.h>
+
+#include    "cssmetric.h"
+
+LOCAL UNITTEST_RESULT test_cssrendering_drawtraversal_1()
+{
+       cssrendering_blockbox_t root;
+       cssrendering_anonymousbox_t anon;
+       cssrendering_linebox_t line[5];
+       cssrendering_drawtraversal_t traversal;
+       cssrendering_drawtraversal_result result;
+       cssmetric_rectangle_t draw;
+       Bool cont, line_called[5] = {False, False, False, False, False};
+       UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+
+       cssrendering_blockbox_initialize(&root);
+       cssrendering_anonymousbox_initialize(&anon);
+       cssrendering_linebox_initialize(line+0);
+       cssrendering_linebox_initialize(line+1);
+       cssrendering_linebox_initialize(line+2);
+       cssrendering_linebox_initialize(line+3);
+       cssrendering_linebox_initialize(line+4);
+
+       cssrendering_blockbox_appendanonymouschild(&root, &anon);
+       cssrendering_anonymousbox_appendchild(&anon, line+0);
+       cssrendering_anonymousbox_appendchild(&anon, line+1);
+       cssrendering_anonymousbox_appendchild(&anon, line+2);
+       cssrendering_anonymousbox_appendchild(&anon, line+3);
+       cssrendering_anonymousbox_appendchild(&anon, line+4);
+
+       line[0].base.content_edge = (cssmetric_rectangle_t){{0, 0, 100, 100}};
+       cssrendering_linebox_setuserdata(line+0, line+0);
+       line[1].base.content_edge = (cssmetric_rectangle_t){{0, 100, 100, 200}};
+       cssrendering_linebox_setuserdata(line+1, line+1);
+       line[2].base.content_edge = (cssmetric_rectangle_t){{0, 200, 100, 300}};
+       cssrendering_linebox_setuserdata(line+2, line+2);
+       line[3].base.content_edge = (cssmetric_rectangle_t){{0, 300, 100, 400}};
+       cssrendering_linebox_setuserdata(line+3, line+3);
+       line[4].base.content_edge = (cssmetric_rectangle_t){{0, 400, 100, 500}};
+       cssrendering_linebox_setuserdata(line+4, line+4);
+
+       draw = (cssmetric_rectangle_t){{25, 150, 75, 350}};
+       cssrendering_drawtraversal_initialize(&traversal, &root, draw);
+       for (;;) {
+               cont = cssrendering_drawtraversal_next(&traversal, &result);
+               if (cont == False) {
+                       break;
+               }
+               if (result.type != CSSRENDERING_DRAWTRAVERSAL_RESULTTYPE_TEXT) {
+                       continue;
+               }
+               if (result.data.text.nodedata == (line+0)) {
+                       line_called[0] = True;
+               } else if (result.data.text.nodedata == (line+1)) {
+                       line_called[1] = True;
+               } else if (result.data.text.nodedata == (line+2)) {
+                       line_called[2] = True;
+               } else if (result.data.text.nodedata == (line+3)) {
+                       line_called[3] = True;
+               } else if (result.data.text.nodedata == (line+4)) {
+                       line_called[4] = True;
+               }
+       }
+       cssrendering_drawtraversal_finalize(&traversal);
+
+       if ((line_called[0] == False)&&(line_called[1] != False)&&(line_called[2] != False)&&(line_called[3] != False)&&(line_called[4] == False)) {
+               ret = UNITTEST_RESULT_PASS;
+       } else {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       cssrendering_linebox_finalize(line+4);
+       cssrendering_linebox_finalize(line+3);
+       cssrendering_linebox_finalize(line+2);
+       cssrendering_linebox_finalize(line+1);
+       cssrendering_linebox_finalize(line+0);
+       cssrendering_anonymousbox_finalize(&anon);
+       cssrendering_blockbox_finalize(&root);
+
+       return ret;
+}
+
+EXPORT VOID test_cssrendering_box_main(unittest_driver_t *driver)
+{
+       UNITTEST_DRIVER_REGIST(driver, test_cssrendering_drawtraversal_1);
+}
diff --git a/src/css/test_cssrendering_coordinate.c b/src/css/test_cssrendering_coordinate.c
new file mode 100644 (file)
index 0000000..2c42a71
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * test_cssrendering_coordinate.c
+ *
+ * Copyright (c) 2013 project bchan
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event will the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ *    claim that you wrote the original software. If you use this software
+ *    in a product, an acknowledgment in the product documentation would be
+ *    appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must not be
+ *    misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source
+ *    distribution.
+ *
+ */
+
+#include "test_css.h"
+
+#include "cssrendering_coordinate.h"
+
+#include       <basic.h>
+#include       <bstdio.h>
+#include       <bstdlib.h>
+#include       <bstring.h>
+
+#include    <unittest_driver.h>
+
+#include    "cssmetric.h"
+
+LOCAL UNITTEST_RESULT test_cssrendering_coordinate_1()
+{
+       cssrendering_coordinate_t coordinate;
+       cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}};
+       RECT src;
+       cssmetric_rectangle_t dest;
+       UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+
+       cssrendering_coordinate_initialize(&coordinate);
+       cssrendering_coordinate_setdrawrect(&coordinate, draw);
+       cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400);
+
+       src = (RECT){{10, 10, 300, 300}};
+       cssrendering_coordinate_getabsoluterect(&coordinate, src, &dest);
+       if ((dest.c.left != 110)||(dest.c.top != 110)||(dest.c.right != 400)||(dest.c.bottom != 400)) {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       cssrendering_coordinate_finalize(&coordinate);
+
+       return ret;
+}
+
+LOCAL UNITTEST_RESULT test_cssrendering_coordinate_2()
+{
+       cssrendering_coordinate_t coordinate;
+       cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}};
+       W x, y;
+       UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+
+       cssrendering_coordinate_initialize(&coordinate);
+       cssrendering_coordinate_setdrawrect(&coordinate, draw);
+       cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400);
+
+       cssrendering_coordinate_getrelativepoint(&coordinate, 110, 120, &x, &y);
+       if ((x != 10)||(y != 20)) {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       cssrendering_coordinate_finalize(&coordinate);
+
+       return ret;
+}
+
+LOCAL UNITTEST_RESULT test_cssrendering_coordinate_3()
+{
+       cssrendering_coordinate_t coordinate;
+       cssmetric_rectangle_t draw = (cssmetric_rectangle_t){{0, 0, 500, 500}};
+       W l, t, r, b;
+       UNITTEST_RESULT ret = UNITTEST_RESULT_PASS;
+
+       cssrendering_coordinate_initialize(&coordinate);
+       cssrendering_coordinate_setdrawrect(&coordinate, draw);
+       cssrendering_coordinate_setviewrect(&coordinate, 100, 100, 400, 400);
+
+       cssrendering_coordinate_scrollviewrect(&coordinate, 30, 40);
+       cssrendering_coordinate_getviewrect(&coordinate, &l, &t, &r, &b);
+       if ((l != 130)||(t != 140)||(r != 430)||(b != 440)) {
+               ret = UNITTEST_RESULT_FAIL;
+       }
+
+       cssrendering_coordinate_finalize(&coordinate);
+
+       return ret;
+}
+
+EXPORT VOID test_cssrendering_coordinate_main(unittest_driver_t *driver)
+{
+       UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_1);
+       UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_2);
+       UNITTEST_DRIVER_REGIST(driver, test_cssrendering_coordinate_3);
+}