diff --git a/src/ntunion.cpp b/src/ntunion.cpp
index 4ae115b..bf055c8 100644
--- a/src/ntunion.cpp
+++ b/src/ntunion.cpp
@@ -18,6 +18,12 @@ static NTFieldPtr ntField = NTField::get();
namespace detail {
+NTUnionBuilder::shared_pointer NTUnionBuilder::value(UnionConstPtr unionType)
+{
+ valueType = unionType;
+ return shared_from_this();
+}
+
StructureConstPtr NTUnionBuilder::createStructure()
{
FieldBuilderPtr builder =
diff --git a/src/pv/ntunion.h b/src/pv/ntunion.h
index 7a65633..86b8054 100644
--- a/src/pv/ntunion.h
+++ b/src/pv/ntunion.h
@@ -40,6 +40,14 @@ namespace detail {
public:
POINTER_DEFINITIONS(NTUnionBuilder);
+ /**
+ * Specifies the union for the value field.
+ * If this is not called then a variant union is the default.
+ * @param unionType the introspection object for the union value field
+ * @return this instance of NTUnionBuilder
+ */
+ shared_pointer value(epics::pvData::UnionConstPtr unionType);
+
/**
* Adds descriptor field to the NTUnion.
* @return this instance of NTUnionBuilder.
diff --git a/test/ntunionTest.cpp b/test/ntunionTest.cpp
index 335edf2..66dab4b 100644
--- a/test/ntunionTest.cpp
+++ b/test/ntunionTest.cpp
@@ -47,7 +47,6 @@ void test_builder()
testOk(valueField.get() != 0, "value is enum");
std::cout << *structure << std::endl;
-
}
void test_ntunion()
@@ -158,11 +157,43 @@ void test_wrap()
testOk(ptr.get() != 0, "wrapUnsafe OK");
}
+
+void test_variant_union()
+{
+ StructureConstPtr structure = NTUnion::createBuilder()->
+ addDescriptor()->
+ addAlarm()->
+ addTimeStamp()->
+ createStructure();
+ testOk1(structure->getField("value")->isVariant());
+}
+
+void test_regular_union()
+{
+ UnionConstPtr u = getFieldCreate()->createFieldBuilder()->
+ add("x", pvDouble)->
+ add("i", pvInt)->
+ createUnion();
+
+ StructureConstPtr structure = NTUnion::createBuilder()->
+ value(u)->
+ addDescriptor()->
+ addAlarm()->
+ addTimeStamp()->
+ createStructure();
+ testOk1(!structure->getField("value")->isVariant());
+ testOk1(structure->getField("value") == u);
+}
+
+
+
MAIN(testNTUnion) {
- testPlan(29);
+ testPlan(32);
test_builder();
test_ntunion();
test_wrap();
+ test_variant_union();
+ test_regular_union();
return testDone();
}