/*
* test_texteditor_characterstate.c
*
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
#include <unittest_driver.h>
typedef struct {
- tadfragment_cursor_segment input;
+ tadsegment input;
struct {
TC *lang;
W lang_len;
LOCAL UNITTEST_RESULT test_texteditor_characterstate_1()
{
test_texteditor_characterstate_t testdata[] = {
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
- {(TC[]){0xFE22}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0x21, 0xFE}, 4},
- {(TC[]){0xFEFE, 0xFE21}, 2, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0x21, 0x00}, 4},
- {(TC[]){0xFEFE, 0x0021}, 2, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0xFE, 0xFE, 0x21, 0xFE}, 6},
- {(TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0xFE, 0xFE, 0xFE, 0xFE, 0x21, 0x00}, 6},
- {(TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, False}
- }
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFE21}, 2, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0x0021}, 2, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, False} },
};
+ TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[0].input.value.lang);
+ TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[1].input.value.lang);
+ TCtotadlangcode((TC[]){0xFEFE, 0xFE21}, 2, &testdata[2].input.value.lang);
+ TCtotadlangcode((TC[]){0xFEFE, 0x0021}, 2, &testdata[3].input.value.lang);
+ TCtotadlangcode((TC[]){0xFEFE, 0xFEFE, 0xFE21}, 3, &testdata[4].input.value.lang);
+ TCtotadlangcode((TC[]){0xFEFE, 0xFEFE, 0x0021}, 3, &testdata[5].input.value.lang);
return test_texteditor_characterstate_common(testdata, 6);
}
LOCAL UNITTEST_RESULT test_texteditor_characterstate_2()
{
test_texteditor_characterstate_t testdata[] = {
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
- {(TC[]){0xFE22}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE22}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, False} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
};
+ testdata[0].input.value.ch = 0x2121;
+ TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[1].input.value.lang);
+ testdata[2].input.value.ch = 0x2121;
+ TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[3].input.value.lang);
+ testdata[4].input.value.ch = 0x2121;
return test_texteditor_characterstate_common(testdata, 5);
}
LOCAL UNITTEST_RESULT test_texteditor_characterstate_3()
{
test_texteditor_characterstate_t testdata[] = {
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
- {(TC[]){0xFE21}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
- {(TC[]){0xFE21}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x01}, 10},
- {(TC[]){0xFE21}, 1, False}
- },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, False} },
};
+ testdata[0].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+ testdata[0].input.value.variable.rawlen = 10;
+ testdata[1].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+ testdata[1].input.value.variable.rawlen = 10;
+ testdata[2].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+ testdata[2].input.value.variable.rawlen = 10;
+ testdata[3].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+ testdata[3].input.value.variable.rawlen = 10;
+ testdata[4].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x01, 0x01};
+ testdata[4].input.value.variable.rawlen = 10;
return test_texteditor_characterstate_common(testdata, 5);
}
LOCAL UNITTEST_RESULT test_texteditor_characterstate_4()
{
test_texteditor_characterstate_t testdata[] = {
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01}, 10},
- {(TC[]){0xFE21}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE21}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x22, 0xFE}, 2},
- {(TC[]){0xFE22}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE22}, 1, True}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00}, 10},
- {(TC[]){0xFE22}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE22}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB[]){0x21, 0xFE}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
- {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB[]){0x21, 0x21}, 2},
- {(TC[]){0xFE21}, 1, False}
- },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE21}, 1, True} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, True} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE22}, 1, True} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, True} },
+ { {TADSEGMENT_TYPE_VARIABLE}, {(TC[]){0xFE22}, 1, False} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE22}, 1, False} },
+ { {TADSEGMENT_TYPE_LANGCODE}, {(TC[]){0xFE21}, 1, False} },
+ { {TADSEGMENT_TYPE_CHARACTOR}, {(TC[]){0xFE21}, 1, False} },
};
+ testdata[0].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x02, 0x01};
+ testdata[0].input.value.variable.rawlen = 10;
+ testdata[1].input.value.ch = 0x2121;
+ TCtotadlangcode((TC[]){0xFE22}, 1, &testdata[2].input.value.lang);
+ testdata[3].input.value.ch = 0x2121;
+ testdata[4].input.value.variable.raw = (UB[]){0xA2, 0xFF, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00};
+ testdata[4].input.value.variable.rawlen = 10;
+ testdata[5].input.value.ch = 0x2121;
+ TCtotadlangcode((TC[]){0xFE21}, 1, &testdata[6].input.value.lang);
+ testdata[7].input.value.ch = 0x2121;
return test_texteditor_characterstate_common(testdata, 8);
}
/*
* texteditor_characterstate.h
*
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
#include <bstdio.h>
-#include <tad/tadfragment.h>
+#include <tad/tadsegment.h>
#include <tad/tadlangcode.h>
#ifdef BCHAN_CONFIG_DEBUG
# define DP_ER(msg, err) /**/
#endif
-EXPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadfragment_cursor_segment *segment)
+EXPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadsegment *segment)
{
- TC *str;
- W len, err;
UB segid, subid;
- if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE) {
- if (segment->len != 10) {
+ if (segment->type == TADSEGMENT_TYPE_VARIABLE) {
+ if (segment->value.variable.rawlen != 10) {
return 0;
}
- segid = *(TC*)segment->p & 0xFF;
+ segid = *(TC*)segment->value.variable.raw & 0xFF;
if (segid != TS_TFONT) {
return 0;
}
- subid = *(TC*)(segment->p + 4) >> 8;
+ subid = *(TC*)(segment->value.variable.raw + 4) >> 8;
if (subid != 3) {
return 0;
}
- state->w_ratio = *(RATIO*)(segment->p + 8);
- } else if (segment->type == TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE) {
- str = (TC*)segment->p;
- len = segment->len / sizeof(TC);
- err = TCtotadlangcode(str, len, &state->lang);
- if (err < 0) {
- return err;
- }
+ state->w_ratio = *(RATIO*)(segment->value.variable.raw + 8);
+ } else if (segment->type == TADSEGMENT_TYPE_LANGCODE) {
+ memcpy(&state->lang, &segment->value.lang, sizeof(tadlangcode));
}
return 0;
}
/*
* texteditor_characterstate.h
*
- * Copyright (c) 2013 project bchan
+ * Copyright (c) 2013-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
*/
#include <basic.h>
+#include <btron/dp.h>
+#include <tad.h>
-#include <tad/tadfragment.h>
+#include <tad/tadsegment.h>
#include <tad/tadlangcode.h>
#ifndef __TEXTEDITOR_CHARACTERSTATE_H__
IMPORT VOID texteditor_characterstate_initialize(texteditor_characterstate_t *state);
IMPORT VOID texteditor_characterstate_finalize(texteditor_characterstate_t *state);
-IMPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadfragment_cursor_segment *segment);
+IMPORT W texteditor_charactorstate_input(texteditor_characterstate_t *state, tadsegment *segment);
IMPORT Bool texteditor_characterstate_ishankaku(texteditor_characterstate_t *state);
IMPORT W texteditor_characterstate_getlang(texteditor_characterstate_t *state, TC *str, W len);
IMPORT VOID texteditor_characterstate_getlangcode(texteditor_characterstate_t *state, tadlangcode *lang);
#include <bstdio.h>
#include <tad/tadfragment.h>
+#include <tad/tadsegment.h>
#include "texteditor_characterstate.h"
#include "texteditor_insertfilter.h"
LOCAL W texteditor_insertcontext_bufferprepair(tadfragment_cursor_t *src, texteditor_characterstate_t *state, tadfragment_cursor_t *dest, W pos)
{
W i, err;
- tadfragment_cursor_segment segment;
+ tadsegment segment;
i = 0;
for (; i < pos;) {
}
texteditor_charactorstate_input(state, &segment);
- if (segment.type == TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR) {
+ if (segment.type == TADSEGMENT_TYPE_CHARACTOR) {
i++;
}
- err = tadfragment_cursor_insert(dest, segment.p, segment.len);
+ err = tadfragment_cursor_insertsegment(dest, &segment);
if (err < 0) {
break;
}
{
texteditor_insertfilter_t filter;
texteditor_insertfilter_result filter_result;
- tadfragment_cursor_segment segment;
+ tadsegment segment;
W err = 0;
Bool cont;
LOCAL W texteditor_insertcontext_bufferafterappend(texteditor_characterstate_t *state, tadfragment_cursor_t *src, tadfragment_cursor_t *dest)
{
- tadfragment_cursor_segment segment;
+ tadsegment segment;
W err = 0;
Bool is_end;
}
texteditor_charactorstate_input(state, &segment);
- err = tadfragment_cursor_insert(dest, segment.p, segment.len);
+ err = tadfragment_cursor_insertsegment(dest, &segment);
if (err < 0) {
break;
}
#include <coll/wordarray.h>
#include "tadlexer_le.h"
#include "tadlangcode.h"
+#include "tadsegment.h"
#ifdef BCHAN_CONFIG_DEBUG
# define DP(arg) printf arg
return err;
}
+EXPORT W tadfragment_cursor_insertsegment(tadfragment_cursor_t *cursor, tadsegment *segment)
+{
+ switch (segment->type) {
+ case TADSEGMENT_TYPE_VARIABLE:
+ return tadfragment_cursor_insert(cursor, segment->value.variable.raw, segment->value.variable.rawlen);
+ case TADSEGMENT_TYPE_CHARACTOR:
+ return tadfragment_cursor_insert(cursor, (UB*)&segment->value.ch, sizeof(TC));
+ case TADSEGMENT_TYPE_LANGCODE:
+ return tadfragment_cursor_insertlang(cursor, &segment->value.lang);
+ }
+ return -1;
+}
+
EXPORT Bool tadfragment_cursor_isend(tadfragment_cursor_t *cursor)
{
return wordarray_cursor_isend(&cursor->base);
}
-EXPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *p)
+EXPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadsegment *p)
{
Bool end;
- W offset, offset_next, err;
+ W offset, offset_next, len, err;
UH ch;
+ TC *buffer;
end = tadfragment_cursor_isend(cursor);
if (end != False) {
return err;
}
- p->p = bytearray_getbuffer(&cursor->target->rawdata) + offset;
- p->len = offset_next - offset;
+ buffer = (TC*)(bytearray_getbuffer(&cursor->target->rawdata) + offset);
+ len = (offset_next - offset) / sizeof(TC);
- ch = *(UH*)p->p;
+ if (len < 1) {
+ return -1;
+ }
+
+ ch = buffer[0];
if ((ch & 0xFF80) == 0xFF80) {
- p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE;
+ p->type = TADSEGMENT_TYPE_VARIABLE;
+ p->value.variable.raw = (UB*)buffer;
+ p->value.variable.rawlen = len * sizeof(TC);
} else if ((ch & 0xFE00) == 0xFE00) {
- p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE;
+ err = TCtotadlangcode(buffer, len, &p->value.lang);
+ if (err < 0) {
+ return err;
+ }
+ p->type = TADSEGMENT_TYPE_LANGCODE;
} else {
- p->type = TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR;
+ p->type = TADSEGMENT_TYPE_CHARACTOR;
+ p->value.ch = buffer[0];
}
return 0;
#include <coll/bytearray.h>
#include <coll/wordarray.h>
#include "tadlangcode.h"
+#include "tadsegment.h"
#ifndef __TADFRAGMENT_H__
#define __TADFRAGMENT_H__
};
typedef struct tadfragment_cursor_t_ tadfragment_cursor_t;
-/* Functionality name: tadfragment */
-/* Detail name: cursor */
-/* Data structure identifier: segment */
-struct tadfragment_cursor_segment_ {
- enum TADFRAGMENT_CURSOR_SEGMENTTYPE {
- TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE,
- TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
- TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE,
- } type;
- UB *p;
- W len;
-};
-typedef struct tadfragment_cursor_segment_ tadfragment_cursor_segment;
-
IMPORT W tadfragment_initialize(tadfragment_t *fragment);
IMPORT VOID tadfragment_finalize(tadfragment_t *fragment);
IMPORT UB* tadfragment_getbuffer(tadfragment_t *fragment);
IMPORT W tadfragment_cursor_erase(tadfragment_cursor_t *cursor, W len);
IMPORT W tadfragment_cursor_insert(tadfragment_cursor_t *cursor, UB *data, W len);
IMPORT W tadfragment_cursor_insertlang(tadfragment_cursor_t *cursor, tadlangcode *lang);
+IMPORT W tadfragment_cursor_insertsegment(tadfragment_cursor_t *cursor, tadsegment *segment);
IMPORT Bool tadfragment_cursor_isend(tadfragment_cursor_t *cursor);
-IMPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *p);
+IMPORT W tadfragment_cursor_getdata(tadfragment_cursor_t *cursor, tadsegment *p);
#endif
#include <tcode.h>
#include "tadlangcode.h"
+#include "tadsegment.h"
#include <unittest_driver.h>
return test_tadfragment_cursor_insertlang_common(&testdata);
}
-LOCAL Bool test_tadfragment_common_verify_segment(tadfragment_cursor_segment *segment, tadfragment_cursor_segment *expected)
+typedef struct {
+ W type;
+ TC *data;
+ W len;
+} test_tadsegment_expected_t;
+
+LOCAL Bool test_tadfragment_common_verify_segment(tadsegment *segment, test_tadsegment_expected_t *expected)
{
Bool result = True;
printf("segment type fail: expected = %d, result = %d\n", expected->type, segment->type);
result = False;
}
- if (segment->len != expected->len) {
- printf("segment length fail: expected = %d, result = %d\n", expected->len, segment->len);
- result = False;
- }
- if (memcmp(segment->p, expected->p, segment->len) != 0) {
- printf("segment data fail\n");
+ switch (segment->type) {
+ case TADSEGMENT_TYPE_VARIABLE:
+ if (segment->value.variable.rawlen != expected->len * sizeof(TC)) {
+ printf("segment length fail: expected = %d, result = %d\n", expected->len * sizeof(TC), segment->value.variable.rawlen);
+ result = False;
+ }
+ if (memcmp(segment->value.variable.raw, expected->data, segment->value.variable.rawlen) != 0) {
+ printf("segment data fail\n");
+ result = False;
+ }
+ break;
+ case TADSEGMENT_TYPE_CHARACTOR:
+ if (expected->len != 1) {
+ printf("charactor length fail\n");
+ result = False;
+ } else if (segment->value.ch != expected->data[0]) {
+ printf("charactor ch fail\n");
+ result = False;
+ }
+ break;
+ case TADSEGMENT_TYPE_LANGCODE:
+ result = tadlangcodecmpTC(expected->data, expected->len, &segment->value.lang);
+ break;
+ default:
result = False;
+ break;
}
return result;
}
-LOCAL Bool test_tadfragment_common_verify_segments(tadfragment_cursor_t *cursor, tadfragment_cursor_segment *expected, W expected_len)
+LOCAL Bool test_tadfragment_common_verify_segments(tadfragment_cursor_t *cursor, test_tadsegment_expected_t *expected, W expected_len)
{
- tadfragment_cursor_segment segment;
+ tadsegment segment;
W i, err;
Bool result = True, verify;
typedef struct {
TC *input;
W input_len;
- tadfragment_cursor_segment *expected;
+ test_tadsegment_expected_t *expected;
W expected_len;
} test_tadfragment_cursor_getdata_t;
{
TC input[] = {TK_A, TK_B, TK_C};
W input_len = sizeof(input);
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_B}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_B}, 1},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 3;
test_tadfragment_cursor_getdata_t testdata = {
{
TC input[] = {TK_A, 0xFF80, 0x0002, 0x0000, TK_C};
W input_len = sizeof(input);
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 3;
test_tadfragment_cursor_getdata_t testdata = {
{
TC input[] = {TK_A, TK_B, 0xFE21};
W input_len = sizeof(input);
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_B}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB*)(TC[]){0xFE21}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_B}, 1},
+ {TADSEGMENT_TYPE_LANGCODE, (TC[]){0xFE21}, 1},
};
W expected_len = 3;
test_tadfragment_cursor_getdata_t testdata = {
{
TC input[] = {TK_A, 0xFEFE, 0xFE21, TK_C};
W input_len = sizeof(input);
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_LANGCODE, (UB*)(TC[]){0xFEFE, 0xFE21}, 4},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_LANGCODE, (TC[]){0xFEFE, 0xFE21}, 2},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 3;
test_tadfragment_cursor_getdata_t testdata = {
W erase_pos;
W erase_len;
Bool expected_pos_after_erase_is_end;
- tadfragment_cursor_segment *expected_pos_after_erase;
- tadfragment_cursor_segment *expected;
+ test_tadsegment_expected_t *expected_pos_after_erase;
+ test_tadsegment_expected_t *expected;
W expected_len;
} test_tadfragment_cursor_erase_t;
{
tadfragment_t fragment;
tadfragment_cursor_t cursor;
- tadfragment_cursor_segment segment;
+ tadsegment segment;
W err;
Bool verify;
UNITTEST_RESULT result = UNITTEST_RESULT_PASS;
TC input[] = {TK_A, 0xFF80, 0x0002, 0x0000, TK_C};
W input_len = sizeof(input);
Bool expected_pos_after_erase_is_end = False;
- tadfragment_cursor_segment expected_pos_after_erase = {
- TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE,
- (UB*)(TC[]){0xFF80, 0x0002, 0x0000},
- 6
+ test_tadsegment_expected_t expected_pos_after_erase = {
+ TADSEGMENT_TYPE_VARIABLE,
+ (TC[]){0xFF80, 0x0002, 0x0000},
+ 3
};
W erase_pos = 0;
W erase_len = 1;
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 2;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 0;
W erase_len = 2;
Bool expected_pos_after_erase_is_end = False;
- tadfragment_cursor_segment expected_pos_after_erase = {
- TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
- (UB*)(TC[]){TK_C},
- 2
+ test_tadsegment_expected_t expected_pos_after_erase = {
+ TADSEGMENT_TYPE_CHARACTOR,
+ (TC[]){TK_C},
+ 1
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 1;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 0;
W erase_len = 3;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
+ test_tadsegment_expected_t expected[] = {
};
W expected_len = 0;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 0;
W erase_len = 4;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
+ test_tadsegment_expected_t expected[] = {
};
W expected_len = 0;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 1;
W erase_len = 1;
Bool expected_pos_after_erase_is_end = False;
- tadfragment_cursor_segment expected_pos_after_erase = {
- TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR,
- (UB*)(TC[]){TK_C},
- 2
+ test_tadsegment_expected_t expected_pos_after_erase = {
+ TADSEGMENT_TYPE_CHARACTOR,
+ (TC[]){TK_C},
+ 1
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_C}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_C}, 1},
};
W expected_len = 2;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 1;
W erase_len = 2;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
};
W expected_len = 1;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 1;
W erase_len = 3;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
};
W expected_len = 1;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 2;
W erase_len = 1;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
};
W expected_len = 2;
test_tadfragment_cursor_erase_t testdata = {
W erase_pos = 2;
W erase_len = 2;
Bool expected_pos_after_erase_is_end = True;
- tadfragment_cursor_segment expected_pos_after_erase = {
+ test_tadsegment_expected_t expected_pos_after_erase = {
};
- tadfragment_cursor_segment expected[] = {
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_CHAR, (UB*)(TC[]){TK_A}, 2},
- {TADFRAGMENT_CURSOR_SEGMENTTYPE_VARIABLE, (UB*)(TC[]){0xFF80, 0x0002, 0x0000}, 6},
+ test_tadsegment_expected_t expected[] = {
+ {TADSEGMENT_TYPE_CHARACTOR, (TC[]){TK_A}, 1},
+ {TADSEGMENT_TYPE_VARIABLE, (TC[]){0xFF80, 0x0002, 0x0000}, 3},
};
W expected_len = 2;
test_tadfragment_cursor_erase_t testdata = {