OSDN Git Service

implement tadsegment_getvariable()
authorornse01 <ornse01@users.sourceforge.jp>
Sun, 17 Aug 2014 16:57:54 +0000 (16:57 +0000)
committerornse01 <ornse01@users.sourceforge.jp>
Sun, 17 Aug 2014 16:57:54 +0000 (16:57 +0000)
git-svn-id: http://svn.sourceforge.jp/svnroot/bchan/bchanf/trunk@622 20a0b8eb-f62a-4a12-8fe1-b598822500fb

src/tad/tadsegment.c [new file with mode: 0644]
src/tad/tadsegment.h
src/tad/test_tadsegment.c [new file with mode: 0644]

diff --git a/src/tad/tadsegment.c b/src/tad/tadsegment.c
new file mode 100644 (file)
index 0000000..c76ffa5
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * tadsegment.c
+ *
+ * Copyright (c) 2014 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 "tadsegment.h"
+
+#include       <basic.h>
+#include       <btron/dp.h>
+#include    <tad.h>
+
+EXPORT W tadsegment_getvariable(tadsegment *segment, UB *segid, UW *seglen, UB **segdata)
+{
+       LTADSEG *seg;
+       TC *ch;
+
+       if (segment->type != TADSEGMENT_TYPE_VARIABLE) {
+               return -1; /* TODO */
+       }
+
+       ch = (TC*)segment->value.variable.raw;
+
+       *segid = *ch & 0xFF;
+       seg = (LTADSEG*)ch;
+       if (seg->len == 0xffff) {
+               *seglen = seg->llen;
+               *segdata = ((UB*)seg) + 8;
+       } else {
+               *seglen = seg->len;
+               *segdata = ((UB*)seg) + 4;
+       }
+
+       return 0;
+}
index ec179f5..2c28706 100644 (file)
@@ -51,4 +51,6 @@ struct tadsegment_ {
 };
 typedef struct tadsegment_ tadsegment;
 
+IMPORT W tadsegment_getvariable(tadsegment *segment, UB *segid, UW *seglen, UB **segdata);
+
 #endif
diff --git a/src/tad/test_tadsegment.c b/src/tad/test_tadsegment.c
new file mode 100644 (file)
index 0000000..a8ef953
--- /dev/null
@@ -0,0 +1,137 @@
+/*
+ * test_texteditor_characterstate.c
+ *
+ * Copyright (c) 2014 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_tad.h"
+
+#include "tadsegment.h"
+
+#include       <basic.h>
+#include       <bstdio.h>
+
+#include    <unittest_driver.h>
+
+LOCAL UNITTEST_RESULT test_tadsegment_1()
+{
+       tadsegment segment;
+       W err;
+       UB segid;
+       UW seglen;
+       UB *segdata;
+       UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
+
+       segment.type = TADSEGMENT_TYPE_VARIABLE;
+       segment.value.variable.raw = (UB*)(TC[]){ 0xFFA2, 0x0006, 0x0300, 0x0101, 0x0101 };
+       segment.value.variable.rawlen = 10;
+
+       err = tadsegment_getvariable(&segment, &segid, &seglen, &segdata);
+       if (err < 0) {
+               return UNITTEST_RESULT_FAIL;
+       }
+
+       if (segid != 0xA2) {
+               result = UNITTEST_RESULT_FAIL;
+       }
+       if (seglen != 6) {
+               result = UNITTEST_RESULT_FAIL;
+       }
+       if (memcmp(segdata, segment.value.variable.raw + 6, seglen) != 0) {
+               result = UNITTEST_RESULT_FAIL;
+       }
+
+       return UNITTEST_RESULT_PASS;
+}
+
+LOCAL UNITTEST_RESULT test_tadsegment_2()
+{
+       tadsegment segment;
+       W err;
+       UB segid;
+       UW seglen;
+       UB *segdata;
+       UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
+
+       segment.type = TADSEGMENT_TYPE_VARIABLE;
+       segment.value.variable.raw = (UB*)(TC[]){ 0xFFE5, 0xFFFF, 0xFF00, 0x0001 };
+       segment.value.variable.rawlen = 0x1FF00 + 8;
+
+       err = tadsegment_getvariable(&segment, &segid, &seglen, &segdata);
+       if (err < 0) {
+               return UNITTEST_RESULT_FAIL;
+       }
+
+       if (segid != 0xE5) {
+               result = UNITTEST_RESULT_FAIL;
+       }
+       if (seglen != 0x1FF00) {
+               result = UNITTEST_RESULT_FAIL;
+       }
+
+       return UNITTEST_RESULT_PASS;
+}
+
+LOCAL UNITTEST_RESULT test_tadsegment_3()
+{
+       tadsegment segment;
+       W err;
+       UB segid;
+       UW seglen;
+       UB *segdata;
+
+       segment.type = TADSEGMENT_TYPE_CHARACTOR;
+
+       err = tadsegment_getvariable(&segment, &segid, &seglen, &segdata);
+       if (err < 0) {
+               return UNITTEST_RESULT_PASS;
+       }
+
+       return UNITTEST_RESULT_FAIL;
+}
+
+LOCAL UNITTEST_RESULT test_tadsegment_4()
+{
+       tadsegment segment;
+       W err;
+       UB segid;
+       UW seglen;
+       UB *segdata;
+
+       segment.type = TADSEGMENT_TYPE_LANGCODE;
+
+       err = tadsegment_getvariable(&segment, &segid, &seglen, &segdata);
+       if (err < 0) {
+               return UNITTEST_RESULT_PASS;
+       }
+
+       return UNITTEST_RESULT_FAIL;
+}
+
+EXPORT VOID test_tadsegment_main(unittest_driver_t *driver)
+{
+       UNITTEST_DRIVER_REGIST(driver, test_tadsegment_1);
+       UNITTEST_DRIVER_REGIST(driver, test_tadsegment_2);
+       UNITTEST_DRIVER_REGIST(driver, test_tadsegment_3);
+       UNITTEST_DRIVER_REGIST(driver, test_tadsegment_4);
+}