Skip to content

Commit

Permalink
added missing testcase, reduce cases of defined but not used
Browse files Browse the repository at this point in the history
  • Loading branch information
maierkomor committed Nov 20, 2022
1 parent d301ea4 commit d43b4a2
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/CppGenerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,8 @@ void CppGenerator::scanRequirements(Message *m)
hasUnused = true;
continue;
}
if (f->isObsolete())
continue;
int id = f->getId();
if ((id == 0) && !target->getFlag("id0"))
error("Use of id 0 requires special considerations. Enable support for it with option id0.");
Expand Down Expand Up @@ -633,36 +635,28 @@ void CppGenerator::scanRequirements(Message *m)
break;
// fixed
case ft_fixed8:
hasU8 = true;
hasWT8 = true;
break;
case ft_fixed16:
hasU16 = true;
hasWT16 = true;
break;
case ft_fixed32:
hasU32 = true;
hasWT32 = true;
break;
case ft_fixed64:
hasU64 = true;
hasWT64 = true;
break;
// sfixed
case ft_sfixed8:
hasS8 = true;
hasWT8 = true;
break;
case ft_sfixed16:
hasS16 = true;
hasWT16 = true;
break;
case ft_sfixed32:
hasS32 = true;
hasWT32 = true;
break;
case ft_sfixed64:
hasS64 = true;
hasWT64 = true;
break;
default:
Expand Down Expand Up @@ -4387,7 +4381,7 @@ void CppGenerator::writeHelpers(vector<unsigned> &funcs)
if (hasCStr || hasString)
funcs.push_back(ct_json_cstr);
funcs.push_back(ct_to_decstr);
if (hasFloat|hasDouble)
if (hasFloat || hasDouble)
funcs.push_back(ct_to_dblstr);
}

Expand All @@ -4409,21 +4403,21 @@ void CppGenerator::writeHelpers(vector<unsigned> &funcs)
funcs.push_back(ct_parse_ascii_dbl);
if (hasFloat)
funcs.push_back(ct_parse_ascii_flt);
if (hasU64)
if (hasU64||hasWT64)
funcs.push_back(ct_parse_ascii_u64);
if (hasU32)
if (hasU32||hasWT32)
funcs.push_back(ct_parse_ascii_u32);
if (hasU16)
if (hasU16||hasWT16)
funcs.push_back(ct_parse_ascii_u16);
if (hasU8)
if (hasU8||hasWT8)
funcs.push_back(ct_parse_ascii_u8);
if (hasS64)
if (hasS64||hasWT64)
funcs.push_back(ct_parse_ascii_s64);
if (hasS32)
if (hasS32||hasWT32)
funcs.push_back(ct_parse_ascii_s32);
if (hasS16)
if (hasS16||hasWT16)
funcs.push_back(ct_parse_ascii_s16);
if (hasS8)
if (hasS8||hasWT8)
funcs.push_back(ct_parse_ascii_s8);
if (hasBytes)
funcs.push_back(ct_parse_ascii_bytes);
Expand Down
10 changes: 10 additions & 0 deletions testsuite/testcases/xint.wfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
option varintbits=32;
option intsize=32;

message xint
{
int8 i8 = 1;
int16 i16 = 2;
sint8 s8 = 3;
sint16 s16 = 4;
}
33 changes: 33 additions & 0 deletions testsuite/testcases/xint_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "xint.h"
#include <assert.h>
#include "runcheck.h"
#include "runcheck.cpp"


int main()
{
xint x;
x.set_i8(-1);
x.set_i16(-1);
x.set_s8(-1);
x.set_s16(-1);
runcheck(x);

x.set_i8(1);
x.set_i16(1);
x.set_s8(1);
x.set_s16(1);
runcheck(x);

x.set_i8(INT8_MAX);
x.set_i16(INT16_MAX);
x.set_s8(INT8_MAX);
x.set_s16(INT16_MAX);
runcheck(x);

x.set_i8(INT8_MIN);
x.set_i16(INT16_MIN);
x.set_s8(INT8_MIN);
x.set_s16(INT16_MIN);
runcheck(x);
}

0 comments on commit d43b4a2

Please sign in to comment.