Skip to content

Commit cdd2dba

Browse files
authored
NGAP-6 copying two DMR members in the m_duplicate method. Also add th… (#393)
* NGAP-6 copying two DMR members in the m_duplicate method. Also add the unit tests. * fix test failure with -asan option
1 parent b3608e0 commit cdd2dba

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎DMR.cc‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ void DMR::m_duplicate(const DMR &dmr) {
7979

8080
d_use_dap4_checksums = dmr.d_use_dap4_checksums;
8181

82+
global_dio_flag = dmr.global_dio_flag;
83+
84+
utf8_xml_encoding = dmr.utf8_xml_encoding;
85+
8286
// Deep copy, using ptr_duplicate()
8387
// d_root can only be a D4Group, so the thing returned by ptr_duplicate() must be a D4Group.
8488
d_root = static_cast<D4Group *>(dmr.d_root->ptr_duplicate());

‎unit-tests/DMRTest.cc‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <cppunit/extensions/HelperMacros.h>
2929
#include <cppunit/extensions/TestFactoryRegistry.h>
3030

31+
#include <memory>
3132
#include <sstream>
3233
#include <string>
3334

@@ -163,6 +164,8 @@ class DMRTest : public TestFixture {
163164
CPPUNIT_TEST(test_copy_ctor_group_d4dim_complex);
164165
CPPUNIT_TEST(test_copy_ctor_group_d4dim_complex_2);
165166
CPPUNIT_TEST(test_copy_ctor_group_d4dim_complex_3);
167+
CPPUNIT_TEST(test_copy_ctor_flags);
168+
CPPUNIT_TEST(test_assignment_flags);
166169

167170
CPPUNIT_TEST_SUITE_END();
168171

@@ -241,6 +244,31 @@ class DMRTest : public TestFixture {
241244
DBG(cerr << __func__ << "() - END" << endl);
242245
}
243246

247+
// m_duplicate() must copy the direct-IO and UTF-8 encoding flags.
248+
void test_copy_ctor_flags() {
249+
unique_ptr<DMR> dmr(build_dmr("test.1", "test.1.das"));
250+
dmr->set_global_dio_flag(true);
251+
dmr->set_utf8_xml_encoding(true);
252+
253+
DMR dmr_2(*dmr);
254+
CPPUNIT_ASSERT(dmr_2.get_global_dio_flag());
255+
CPPUNIT_ASSERT(dmr_2.get_utf8_xml_encoding());
256+
}
257+
258+
void test_assignment_flags() {
259+
unique_ptr<DMR> dmr(build_dmr("test.1", "test.1.das"));
260+
dmr->set_global_dio_flag(true);
261+
dmr->set_utf8_xml_encoding(true);
262+
263+
D4BaseTypeFactory factory;
264+
DMR dmr_2(&factory, "dest");
265+
CPPUNIT_ASSERT(!dmr_2.get_global_dio_flag());
266+
CPPUNIT_ASSERT(!dmr_2.get_utf8_xml_encoding());
267+
dmr_2 = *dmr;
268+
CPPUNIT_ASSERT(dmr_2.get_global_dio_flag());
269+
CPPUNIT_ASSERT(dmr_2.get_utf8_xml_encoding());
270+
}
271+
244272
// This tests if using the copy still works after the original is deleted
245273
void test_copy_ctor_2() {
246274
DBG(cerr << endl << __func__ << "() - BEGIN" << endl);

0 commit comments

Comments
 (0)