Author: sbanacho
Date: Tue Nov 3 18:25:24 2009
New Revision: 832499
URL: http://svn.apache.org/viewvc?rev=832499&view=rev
Log:
AVRO-180. Enhance code generator script and unit tests.
Modified:
hadoop/avro/trunk/CHANGES.txt
hadoop/avro/trunk/src/c++/Makefile.in
hadoop/avro/trunk/src/c++/api/NodeImpl.hh
hadoop/avro/trunk/src/c++/api/ValidSchema.hh
hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
hadoop/avro/trunk/src/c++/impl/Validator.cc
hadoop/avro/trunk/src/c++/jsonschemas/bigrecord
hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py
hadoop/avro/trunk/src/c++/test/testgen.cc
hadoop/avro/trunk/src/c++/test/unittest.cc
Modified: hadoop/avro/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Nov 3 18:25:24 2009
@@ -10,6 +10,8 @@
IMPROVEMENTS
+ AVRO-180. Enhance code generator script and unit tests. (sbanacho)
+
AVRO-157. Changes from code review comments for C++. (sbanacho)
AVRO-168. Correct shared library versioning for C implementation (massie)
Modified: hadoop/avro/trunk/src/c++/Makefile.in
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/Makefile.in?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/Makefile.in (original)
+++ hadoop/avro/trunk/src/c++/Makefile.in Tue Nov 3 18:25:24 2009
@@ -40,10 +40,11 @@
EXECS = unittest testparser precompile testgen
EXECSDIR = obj
-AVROEXECS = $(EXECS:%=$(EXECSDIR)/%)
+AVRO_EXECS = $(EXECS:%=$(EXECSDIR)/%)
INCFLAGS = -I$(AVROINCLUDES) -I$(AVROPARSER)
INCFLAGS += $(BOOST_CPPFLAGS)
+TEST_INCFLAGS = $(INCFLAGS) -I$(OBJDIR)
LIBS += $(BOOST_LDFLAGS) $(BOOST_REGEX_LIB)
@@ -62,9 +63,9 @@
GENERATEDobjs = $(addsuffix .o, $(sort $(basename $(GENERATED))) )
GENERATEDOBJS = $(GENERATEDobjs:%=$(OBJDIR)/%)
-all : $(AVRO_STATIC) $(AVRO_DYNAMIC) $(AVROEXECS)
+all : $(AVRO_STATIC) $(AVRO_DYNAMIC) $(AVRO_EXECS)
-check: $(AVROEXECS)
+check: $(AVRO_EXECS)
$(EXECSDIR)/testparser < $(AVROSCHEMAS)/bigrecord
$(EXECSDIR)/unittest
$(EXECSDIR)/testgen $(AVROSCHEMAS)/bigrecord
@@ -103,12 +104,12 @@
$(EXECSDIR)/precompile: $(AVROTEST)/precompile.cc $(AVRO_STATIC)
$(CXX) $(CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LIBS)
-$(AVROTEST)/code.hh: $(AVROSCRIPTS)/gen-cppcode.py $(EXECSDIR)/precompile
$(AVROSCHEMAS)/bigrecord
+$(OBJDIR)/code.hh: $(AVROSCRIPTS)/gen-cppcode.py $(EXECSDIR)/precompile
$(AVROSCHEMAS)/bigrecord
$(EXECSDIR)/precompile < $(AVROSCHEMAS)/bigrecord > obj/bigrecord.flat
- $(PYTHON) $(AVROSCRIPTS)/gen-cppcode.py < obj/bigrecord.flat >
$(AVROTEST)/code.hh
+ $(PYTHON) $(AVROSCRIPTS)/gen-cppcode.py -n testgen -i
obj/bigrecord.flat -o $(OBJDIR)/code.hh
-$(EXECSDIR)/testgen: $(AVROTEST)/code.hh $(AVROTEST)/testgen.cc $(AVRO_STATIC)
- $(CXX) $(CXXFLAGS) $(INCFLAGS) -o $@ $^ $(LIBS)
+$(EXECSDIR)/testgen: $(AVROTEST)/testgen.cc $(OBJDIR)/code.hh $(AVRO_STATIC)
+ $(CXX) $(CXXFLAGS) $(TEST_INCFLAGS) -o $@ $(LIBS) $< $(AVRO_STATIC)
CPP_DOC_DIR ?= "./doc"
@@ -126,4 +127,4 @@
cp $(HEADERS) $(prefix)/include/avro
clean :
- rm -rf $(AVROEXECS) $(OBJS) $(AVRO_STATIC) $(GENERATEDSRCS)
$(GENERATEDOBJS) core
+ rm -rf $(AVRO_EXECS) $(OBJS) $(AVRO_STATIC) $(GENERATEDSRCS)
$(GENERATEDOBJS) core
Modified: hadoop/avro/trunk/src/c++/api/NodeImpl.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/NodeImpl.hh?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/NodeImpl.hh (original)
+++ hadoop/avro/trunk/src/c++/api/NodeImpl.hh Tue Nov 3 18:25:24 2009
@@ -215,7 +215,7 @@
bool isValid() const {
return (
(nameAttribute_.size() == 1) &&
- (leafNameAttributes_.size() > 1)
+ (leafNameAttributes_.size() > 0)
);
}
};
Modified: hadoop/avro/trunk/src/c++/api/ValidSchema.hh
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/ValidSchema.hh?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/ValidSchema.hh (original)
+++ hadoop/avro/trunk/src/c++/api/ValidSchema.hh Tue Nov 3 18:25:24 2009
@@ -52,6 +52,10 @@
return node_;
}
+ const Type rootType() const {
+ return node_->type();
+ }
+
void toJson(std::ostream &os) const;
void toFlatList(std::ostream &os) const;
Modified: hadoop/avro/trunk/src/c++/impl/NodeImpl.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/NodeImpl.cc?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/NodeImpl.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/NodeImpl.cc Tue Nov 3 18:25:24 2009
@@ -147,7 +147,7 @@
os << "{\n";
os << indent(++depth) << "\"type\": \"fixed\",\n";
os << indent(depth) << "\"size\": " << sizeAttribute_.get() << ",\n";
- os << indent(depth) << "\"name\": " << nameAttribute_.get() << "\"\n";
+ os << indent(depth) << "\"name\": \"" << nameAttribute_.get() << "\"\n";
os << indent(--depth) << '}';
}
Modified: hadoop/avro/trunk/src/c++/impl/Validator.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/impl/Validator.cc?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/impl/Validator.cc (original)
+++ hadoop/avro/trunk/src/c++/impl/Validator.cc Tue Nov 3 18:25:24 2009
@@ -192,6 +192,10 @@
((this)->*(func))();
}
+
+ if(compoundStack_.empty()) {
+ nextType_ = AVRO_NULL;
+ }
}
void
@@ -243,7 +247,8 @@
if(nextType_ == AVRO_SYMBOLIC) {
NodePtr symNode ( schema_.followSymbol(node->name()) );
assert(symNode);
- return setupOperation(symNode);
+ setupOperation(symNode);
+ return;
}
assert(nextType_ < AVRO_NUM_TYPES);
Modified: hadoop/avro/trunk/src/c++/jsonschemas/bigrecord
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/jsonschemas/bigrecord?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/jsonschemas/bigrecord (original)
+++ hadoop/avro/trunk/src/c++/jsonschemas/bigrecord Tue Nov 3 18:25:24 2009
@@ -7,6 +7,27 @@
"type": "long"
},
{
+ "name": "nestedrecord",
+ "type": {
+ "type": "record",
+ "name": "Nested",
+ "fields": [
+ {
+ "name": "inval1",
+ "type": "double"
+ },
+ {
+ "name": "inval2",
+ "type": "string"
+ },
+ {
+ "name": "inval3",
+ "type": "int"
+ }
+ ]
+ }
+ },
+ {
"name": "mymap",
"type": {
"type": "map",
@@ -56,6 +77,10 @@
"type": "boolean"
},
{
+ "name": "anothernested",
+ "type": "Nested"
+ },
+ {
"name": "myfixed",
"type": {
"type": "fixed",
Modified: hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/scripts/gen-cppcode.py?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py (original)
+++ hadoop/avro/trunk/src/c++/scripts/gen-cppcode.py Tue Nov 3 18:25:24 2009
@@ -59,13 +59,13 @@
$recordfields$};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
s.writeRecord();
$serializefields$
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
p.readRecord();
$parsefields$
}
@@ -85,7 +85,7 @@
elif line[0] == 'name':
fieldname = line[1]
fieldline = getNextLine()
- fieldtypename, fieldtype = genCode(fieldline)
+ fieldtypename, fieldtype = processType(fieldline)
fields += ' ' + fieldtypename + ' ' + fieldname + ';\n'
serializefields += ' serialize(s, val.' + fieldname + ');\n'
parsefields += ' parse(p, val.' + fieldname + ');\n'
@@ -120,7 +120,7 @@
};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
s.writeUnion(val.choice);
switch(val.choice) {
$switchserialize$
@@ -130,7 +130,7 @@
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.choice = p.readUnion();
switch(val.choice) {
$switchparse$
@@ -162,7 +162,7 @@
line = getNextLine()
if line[0] == 'end': end = True
else :
- uniontype, name = genCode(line)
+ uniontype, name = processType(line)
typename += '_' + name
uniontypes += ' ' + 'typedef ' + uniontype + ' T' + str(i) +
';\n'
switch = unionser
@@ -195,12 +195,12 @@
};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
s.writeEnum(val.value);
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.value = static_cast<$name$::EnumSymbols>(p.readEnum());
}
'''
@@ -234,7 +234,7 @@
};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
const size_t size = val.value.size();
if(size) {
s.writeArrayBlock(size);
@@ -246,7 +246,7 @@
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.value.clear();
while(1) {
int size = p.readArrayBlockSize();
@@ -267,7 +267,7 @@
def doArray(args):
structDef = arrayTemplate
line = getNextLine()
- arraytype, typename = genCode(line);
+ arraytype, typename = processType(line);
typename = 'Array_of_' + typename
structDef = structDef.replace('$name$', typename)
@@ -291,7 +291,7 @@
};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
if(val.value.size()) {
s.writeMapBlock(val.value.size());
$name$::MapType::const_iterator iter = val.value.begin();
@@ -306,7 +306,7 @@
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
val.value.clear();
while(1) {
int size = p.readMapBlockSize();
@@ -330,7 +330,7 @@
structDef = mapTemplate
line = getNextLine() # must be string
line = getNextLine()
- maptype, typename = genCode(line);
+ maptype, typename = processType(line);
typename = 'Map_of_' + typename
structDef = structDef.replace('$name$', typename);
@@ -349,12 +349,12 @@
};
template <typename Serializer>
-void serialize(Serializer &s, const $name$ &val, const boost::true_type &) {
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
s.writeFixed(val.value, $name$::fixedSize);
}
template <typename Parser>
-void parse(Parser &p, $name$ &val, const boost::true_type &) {
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
p.readFixed(val.value, $name$::fixedSize);
}
'''
@@ -372,10 +372,32 @@
addStruct(typename, structDef)
return (typename,typename)
+primitiveTemplate = '''struct $name$ {
+ $type$ value;
+};
+
+template <typename Serializer>
+inline void serialize(Serializer &s, const $name$ &val, const boost::true_type
&) {
+ s.writeValue(val.value);
+}
+
+template <typename Parser>
+inline void parse(Parser &p, $name$ &val, const boost::true_type &) {
+ p.readValue(val.value);
+}
+'''
+
+def doPrimitiveStruct(type):
+ structDef = primitiveTemplate
+ name = type.capitalize()
+ structDef = structDef.replace('$name$', name);
+ structDef = structDef.replace('$type$', typeToC[type]);
+ addStruct(name, structDef)
+
compoundBuilder= { 'record' : doRecord, 'union' : doUnion, 'enum' : doEnum,
'map' : doMap, 'array' : doArray, 'fixed' : doFixed, 'symbolic' : doSymbolic }
-def genCode(inputs) :
+def processType(inputs) :
type = inputs[0]
if typeToC.has_key(type) :
result = doPrimitive(type)
@@ -384,6 +406,15 @@
result = func(inputs)
return result
+def generateCode() :
+ inputs = getNextLine()
+ type = inputs[0]
+ if typeToC.has_key(type) :
+ doPrimitiveStruct(type)
+ else :
+ func = compoundBuilder[type]
+ func(inputs)
+
def getNextLine():
try:
line = raw_input()
@@ -395,16 +426,7 @@
globals()["done"] = True
return line.split(' ')
-if __name__ == "__main__":
- from sys import argv
- if(len(argv) > 1):
- namespace = argv[1]
- else:
- namespace = 'avrouser'
-
- inputs = getNextLine()
- genCode(inputs)
-
+def writeHeader():
print "#ifndef %s_AvroGenerated_hh__" % namespace
print "#define %s_AvroGenerated_hh__" % namespace
print headers
@@ -426,3 +448,63 @@
print "#endif // %s_AvroGenerated_hh__" % namespace
+
+def usage():
+ print "-h, --help print this helpful message"
+ print "-i, --input=FILE input file to read (default is stdin)"
+ print "-o, --output=PATH output file to generate (default is stdout)"
+ print "-n, --namespace=LABEL namespace for schema (default is avrouser)"
+
+if __name__ == "__main__":
+ from sys import argv
+ import getopt,sys
+
+ try:
+ opts, args = getopt.getopt(argv[1:], "hi:o:n:", ["help", "input=",
"output=", "namespace="])
+
+ except getopt.GetoptError, err:
+ print str(err)
+ usage()
+ sys.exit(2)
+
+ namespace = 'avrouser'
+
+ savein = sys.stdin
+ saveout = sys.stdout
+ inputFile = False
+ outputFile = False
+
+ for o, a in opts:
+ if o in ("-i", "--input"):
+ try:
+ inputFile = open(a, 'r')
+ sys.stdin = inputFile
+ except:
+ print "Could not open file " + a
+ sys.exit()
+ elif o in ("-o", "--output"):
+ try:
+ outputFile = open(a, 'w')
+ sys.stdout = outputFile
+ except:
+ print "Could not open file " + a
+ elif o in ("-n", "--namespace"):
+ namespace = a
+ elif o in ("-h", "--help"):
+ usage()
+ sys.exit()
+ else:
+ print "Unhandled option: " + o
+ usage()
+ sys.exit()
+
+ generateCode()
+ writeHeader()
+
+ sys.stdin = savein
+ sys.stdout = saveout
+ if inputFile:
+ inputFile.close()
+ if outputFile:
+ outputFile.close()
+
Modified: hadoop/avro/trunk/src/c++/test/testgen.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/testgen.cc?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/testgen.cc (original)
+++ hadoop/avro/trunk/src/c++/test/testgen.cc Tue Nov 3 18:25:24 2009
@@ -34,7 +34,7 @@
std::string gInputSchema ("jsonschemas/bigrecord");
-void serialize(const avrouser::RootRecord &rec)
+void serializeToScreen(const testgen::RootRecord &rec)
{
avro::ScreenStreamer os;
avro::Writer writer(os);
@@ -42,7 +42,7 @@
avro::serialize(writer, rec);
}
-void serializeValid(const avro::ValidSchema &valid, const avrouser::RootRecord
&rec)
+void serializeToScreenValid(const avro::ValidSchema &valid, const
testgen::RootRecord &rec)
{
avro::ScreenStreamer os;
avro::ValidatingWriter writer(valid, os);
@@ -50,7 +50,7 @@
avro::serialize(writer, rec);
}
-void checkArray(const avrouser::Array_of_double &a1, const
avrouser::Array_of_double &a2)
+void checkArray(const testgen::Array_of_double &a1, const
testgen::Array_of_double &a2)
{
BOOST_CHECK_EQUAL(a1.value.size(), 3U);
BOOST_CHECK_EQUAL(a1.value.size(), a2.value.size());
@@ -59,12 +59,12 @@
}
}
-void checkMap(const avrouser::Map_of_int &map1, const avrouser::Map_of_int
&map2)
+void checkMap(const testgen::Map_of_int &map1, const testgen::Map_of_int
&map2)
{
BOOST_CHECK_EQUAL(map1.value.size(), map2.value.size());
- avrouser::Map_of_int::MapType::const_iterator iter1 = map1.value.begin();
- avrouser::Map_of_int::MapType::const_iterator end = map1.value.end();
- avrouser::Map_of_int::MapType::const_iterator iter2 = map2.value.begin();
+ testgen::Map_of_int::MapType::const_iterator iter1 = map1.value.begin();
+ testgen::Map_of_int::MapType::const_iterator end = map1.value.end();
+ testgen::Map_of_int::MapType::const_iterator iter2 = map2.value.begin();
while(iter1 != end) {
BOOST_CHECK_EQUAL(iter1->first, iter2->first);
@@ -83,9 +83,18 @@
}
}
-void checkOk(const avrouser::RootRecord &rec1, const avrouser::RootRecord
&rec2)
+void checkNested(const testgen::Nested &rec1, const testgen::Nested &rec2)
+{
+ BOOST_CHECK_EQUAL(rec1.inval1, rec2.inval1);
+ BOOST_CHECK_EQUAL(rec1.inval2, rec2.inval2);
+ BOOST_CHECK_EQUAL(rec1.inval3, rec2.inval3);
+}
+
+void checkOk(const testgen::RootRecord &rec1, const testgen::RootRecord &rec2)
{
BOOST_CHECK_EQUAL(rec1.mylong, rec1.mylong);
+
+ checkNested(rec1.nestedrecord, rec2.nestedrecord);
checkMap(rec1.mymap, rec2.mymap);
checkArray(rec1.myarray, rec2.myarray);
@@ -95,7 +104,7 @@
// in this test I know choice was 1
{
BOOST_CHECK_EQUAL(rec1.myunion.choice, 1);
- checkMap(rec1.myunion.getValue<avrouser::Map_of_int>(),
rec2.myunion.getValue<avrouser::Map_of_int>());
+ checkMap(rec1.myunion.getValue<testgen::Map_of_int>(),
rec2.myunion.getValue<testgen::Map_of_int>());
}
BOOST_CHECK_EQUAL(rec1.anotherunion.choice, rec2.anotherunion.choice);
@@ -103,17 +112,20 @@
{
BOOST_CHECK_EQUAL(rec1.anotherunion.choice, 0);
typedef std::vector<uint8_t> mytype;
- checkBytes(rec1.anotherunion.getValue<mytype>(),
rec2.anotherunion.getValue<avrouser::Union_of_bytes_null::T0>());
+ checkBytes(rec1.anotherunion.getValue<mytype>(),
rec2.anotherunion.getValue<testgen::Union_of_bytes_null::T0>());
}
+ checkNested(rec1.anothernested, rec2.anothernested);
+
BOOST_CHECK_EQUAL(rec1.mybool, rec2.mybool);
- for(int i = 0; i < static_cast<int>(avrouser::md5::fixedSize); ++i) {
+
+ for(int i = 0; i < static_cast<int>(testgen::md5::fixedSize); ++i) {
BOOST_CHECK_EQUAL(rec1.myfixed.value[i], rec2.myfixed.value[i]);
}
BOOST_CHECK_EQUAL(rec1.anotherint, rec1.anotherint);
}
-void testParser(const avrouser::RootRecord &myRecord)
+void testParser(const testgen::RootRecord &myRecord)
{
std::ostringstream ostring;
avro::OStreamer os(ostring);
@@ -121,7 +133,7 @@
avro::serialize(s, myRecord);
- avrouser::RootRecord inRecord;
+ testgen::RootRecord inRecord;
std::istringstream istring(ostring.str());
avro::IStreamer is(istring);
avro::Reader p(is);
@@ -130,7 +142,7 @@
checkOk(myRecord, inRecord);
}
-void testParserValid(avro::ValidSchema &valid, const avrouser::RootRecord
&myRecord)
+void testParserValid(avro::ValidSchema &valid, const testgen::RootRecord
&myRecord)
{
std::ostringstream ostring;
avro::OStreamer os(ostring);
@@ -138,7 +150,7 @@
avro::serialize(s, myRecord);
- avrouser::RootRecord inRecord;
+ testgen::RootRecord inRecord;
std::istringstream istring(ostring.str());
avro::IStreamer is(istring);
avro::ValidatingReader p(valid, is);
@@ -147,17 +159,17 @@
checkOk(myRecord, inRecord);
}
-void runTests(const avrouser::RootRecord myRecord)
+void runTests(const testgen::RootRecord myRecord)
{
std::cout << "Serialize:\n";
- serialize(myRecord);
+ serializeToScreen(myRecord);
std::cout << "end Serialize\n";
avro::ValidSchema schema;
std::ifstream in(gInputSchema.c_str());
avro::compileJsonSchema(in, schema);
std::cout << "Serialize validated:\n";
- serializeValid(schema, myRecord);
+ serializeToScreenValid(schema, myRecord);
std::cout << "end Serialize validated\n";
testParser(myRecord);
@@ -169,14 +181,17 @@
{
uint8_t fixed[] = {0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
- avrouser::RootRecord myRecord;
+ testgen::RootRecord myRecord;
myRecord.mylong = 212;
+ myRecord.nestedrecord.inval1 = std::numeric_limits<double>::min();
+ myRecord.nestedrecord.inval2 = "hello world";
+ myRecord.nestedrecord.inval3 = std::numeric_limits<int32_t>::max();
myRecord.mymap.value.clear();
myRecord.myarray.addValue(3434.9);
myRecord.myarray.addValue(7343.9);
myRecord.myarray.addValue(-63445.9);
- myRecord.myenum.value = avrouser::ExampleEnum::one;
- avrouser::Map_of_int map;
+ myRecord.myenum.value = testgen::ExampleEnum::one;
+ testgen::Map_of_int map;
map.addValue("one", 1);
map.addValue("two", 2);
myRecord.myunion.set_Map_of_int(map);
@@ -185,7 +200,10 @@
vec.push_back(2);
myRecord.anotherunion.set_bytes(vec);
myRecord.mybool = true;
- memcpy(myRecord.myfixed.value, fixed, avrouser::md5::fixedSize);
+ myRecord.anothernested.inval1 = std::numeric_limits<double>::max();
+ myRecord.anothernested.inval2 = "goodbye world";
+ myRecord.anothernested.inval3 = std::numeric_limits<int32_t>::min();
+ memcpy(myRecord.myfixed.value, fixed, testgen::md5::fixedSize);
myRecord.anotherint = 4534;
myRecord.bytes.push_back(10);
myRecord.bytes.push_back(20);
Modified: hadoop/avro/trunk/src/c++/test/unittest.cc
URL:
http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/test/unittest.cc?rev=832499&r1=832498&r2=832499&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/test/unittest.cc (original)
+++ hadoop/avro/trunk/src/c++/test/unittest.cc Tue Nov 3 18:25:24 2009
@@ -72,6 +72,11 @@
record.addField("myunion", onion);
+ RecordSchema nestedRecord("NestedRecord");
+ nestedRecord.addField("floatInNested", FloatSchema());
+
+ record.addField("nested", nestedRecord);
+
record.addField("mybool", BoolSchema());
FixedSchema fixed(16, "fixed16");
record.addField("myfixed", fixed);
@@ -133,6 +138,10 @@
std::cout << "Union\n";
printUnion(s, path);
+ std::cout << "Record\n";
+ s.writeRecord();
+ s.writeFloat(-101.101f);
+
std::cout << "Bool\n";
s.writeBool(true);
@@ -224,10 +233,22 @@
}
template <typename Parser>
+ void readNestedRecord(Parser &p)
+ {
+ printNext(p);
+ p.readRecord();
+ printNext(p);
+ float f = p.readFloat();
+ std::cout << f << '\n';
+ BOOST_CHECK_EQUAL(f, -101.101f);
+ }
+
+ template <typename Parser>
void readFixed(Parser &p) {
std::vector<uint8_t> input;
p.readFixed(input, 16);
+ BOOST_CHECK_EQUAL(input.size(), 16U);
for(int i=0; i< 16; ++i) {
std::cout << static_cast<int>(input[i]) << ' ';
@@ -258,6 +279,8 @@
std::cout << "Union path " << longval << '\n';
readMap(p);
+ readNestedRecord(p);
+
printNext(p);
bool boolval = p.readBool();
std::cout << boolval << '\n';