diff --git a/test/clib/test_clib.cpp b/test/clib/test_clib.cpp index a2b5128581..65f4dc869c 100644 --- a/test/clib/test_clib.cpp +++ b/test/clib/test_clib.cpp @@ -10,14 +10,11 @@ using ::testing::HasSubstr; string reportError() { - int buflen = 0; - char* output_buf = 0; - buflen = ct_getCanteraError(buflen, output_buf) + 1; - output_buf = new char[buflen]; - ct_getCanteraError(buflen, output_buf); - string err = output_buf; - delete[] output_buf; - return err; + vector output_buf; + int buflen = ct_getCanteraError(0, output_buf.data()) + 1; + output_buf.resize(buflen); + ct_getCanteraError(buflen, output_buf.data()); + return string(output_buf.data()); } TEST(ct, cabinet_exceptions) @@ -62,11 +59,10 @@ TEST(ct, new_solution) int thermo = soln_thermo(ref); ASSERT_EQ(thermo_parent(thermo), ref); - char* buf = new char[buflen]; - soln_name(ref, buflen, buf); - string solName = buf; + vector buf(buflen); + soln_name(ref, buflen, buf.data()); + string solName(buf.data()); ASSERT_EQ(solName, name); - delete[] buf; } TEST(ct, soln_objects) @@ -142,19 +138,17 @@ TEST(ct, new_interface) int ph_surf = soln_thermo(surf); int buflen = soln_name(ph_surf, 0, 0) + 1; // include \0 - char* buf = new char[buflen]; - soln_name(ph_surf, buflen, buf); - string solName = buf; + vector buf(buflen); + soln_name(ph_surf, buflen, buf.data()); + string solName(buf.data()); ASSERT_EQ(solName, "Pt_surf"); - delete[] buf; int kin_surf = soln_kinetics(surf); buflen = kin_getType(kin_surf, 0, 0) + 1; // include \0 - buf = new char[buflen]; - kin_getType(ph_surf, buflen, buf); - string kinType = buf; + buf.resize(buflen); + kin_getType(ph_surf, buflen, buf.data()); + string kinType(buf.data()); ASSERT_EQ(kinType, "surface"); - delete[] buf; } TEST(ct, new_interface_auto) @@ -170,18 +164,16 @@ TEST(ct, new_interface_auto) ASSERT_EQ(gas, 1); int buflen = soln_name(gas, 0, 0) + 1; // include \0 - char* buf = new char[buflen]; - soln_name(gas, buflen, buf); - string solName = buf; + vector buf(buflen); + soln_name(gas, buflen, buf.data()); + string solName(buf.data()); ASSERT_EQ(solName, "gas"); - delete[] buf; buflen = soln_adjacentName(surf, 0, 0, 0) + 1; - char* buf2 = new char[buflen]; - soln_adjacentName(surf, 0, buflen, buf2); - solName = buf2; + buf.resize(buflen); + soln_adjacentName(surf, 0, buflen, buf.data()); + solName = buf.data(); ASSERT_EQ(solName, "gas"); - delete[] buf2; } TEST(ct, thermo) diff --git a/test/clib/test_ctfunc.cpp b/test/clib/test_ctfunc.cpp index 80332d3c84..bacc31d97d 100644 --- a/test/clib/test_ctfunc.cpp +++ b/test/clib/test_ctfunc.cpp @@ -27,11 +27,10 @@ TEST(ctfunc, sin) EXPECT_DOUBLE_EQ(func_value(dfcn, 0.5), omega * cos(omega * 0.5)); int buflen = func_write(fcn, "x", 0, 0); - char* buf = new char[buflen]; - func_write(fcn, "x", buflen, buf); - string rep = buf; + vector buf(buflen); + func_write(fcn, "x", buflen, buf.data()); + string rep(buf.data()); ASSERT_EQ(rep, "\\sin(2.1x)"); - delete[] buf; } TEST(ctfunc, cos) @@ -123,11 +122,10 @@ TEST(ctfunc, poly) params = {1, 0, -2.2, 3.1}; fcn = func_new_advanced("polynomial3", params.size(), params.data()); int buflen = func_write(fcn, "x", 0, 0); - char* buf = new char[buflen]; - func_write(fcn, "x", buflen, buf); - string rep = buf; + vector buf(buflen); + func_write(fcn, "x", buflen, buf.data()); + string rep(buf.data()); ASSERT_EQ(rep, "x^3 - 2.2x + 3.1"); - delete[] buf; } TEST(ctfunc, Fourier) diff --git a/test/clib/test_ctonedim.cpp b/test/clib/test_ctonedim.cpp index 6325835b91..3e4f45d20b 100644 --- a/test/clib/test_ctonedim.cpp +++ b/test/clib/test_ctonedim.cpp @@ -29,11 +29,10 @@ TEST(ctonedim, freeflow) ASSERT_NEAR(flow1D_pressure(flow), P, 1e-5); int buflen = domain_type(flow, 0, 0); - char* buf = new char[buflen]; - domain_type(flow, buflen, buf); - string domType = buf; + vector buf(buflen); + domain_type(flow, buflen, buf.data()); + string domType(buf.data()); ASSERT_EQ(domType, "free-flow"); - delete[] buf; } TEST(ctonedim, inlet) @@ -43,11 +42,10 @@ TEST(ctonedim, inlet) ASSERT_GE(inlet, 0); int buflen = domain_type(inlet, 0, 0); - char* buf = new char[buflen]; - domain_type(inlet, buflen, buf); - string domType = buf; + vector buf(buflen); + domain_type(inlet, buflen, buf.data()); + string domType(buf.data()); ASSERT_EQ(domType, "inlet"); - delete[] buf; } TEST(ctonedim, outlet) @@ -57,11 +55,10 @@ TEST(ctonedim, outlet) ASSERT_GE(outlet, 0); int buflen = domain_type(outlet, 0, 0); - char* buf = new char[buflen]; - domain_type(outlet, buflen, buf); - string domType = buf; + vector buf(buflen); + domain_type(outlet, buflen, buf.data()); + string domType(buf.data()); ASSERT_EQ(domType, "outlet"); - delete[] buf; } TEST(ctonedim, reacting_surface) @@ -71,11 +68,10 @@ TEST(ctonedim, reacting_surface) ASSERT_GE(surf, 0); int buflen = domain_type(surf, 0, 0); - char* buf = new char[buflen]; - domain_type(surf, buflen, buf); - string domType = buf; + vector buf(buflen); + domain_type(surf, buflen, buf.data()); + string domType(buf.data()); ASSERT_EQ(domType, "reacting-surface"); - delete[] buf; } TEST(ctonedim, catcomb) @@ -170,11 +166,11 @@ TEST(ctonedim, freeflame) for (size_t i = 0; i < nsp; i++) { value = {yin[i], yin[i], yout[i], yout[i]}; int buflen = thermo_getSpeciesName(ph, i, 0, 0) + 1; // include \0 - char* buf = new char[buflen]; - thermo_getSpeciesName(ph, i, buflen, buf); - string name = buf; + vector buf(buflen); + thermo_getSpeciesName(ph, i, buflen, buf.data()); + string name(buf.data()); ASSERT_EQ(name, gas->speciesName(i)); - comp = static_cast(domain_componentIndex(flow, buf)); + comp = static_cast(domain_componentIndex(flow, buf.data())); sim1D_setProfile(flame, dom, comp, 4, locs.data(), 4, value.data()); } diff --git a/test/clib/test_ctreactor.cpp b/test/clib/test_ctreactor.cpp index cd84174383..bda8ba4d29 100644 --- a/test/clib/test_ctreactor.cpp +++ b/test/clib/test_ctreactor.cpp @@ -17,11 +17,10 @@ TEST(ctreactor, reactor_soln) int ret = reactor_setName(reactor, "spam"); ASSERT_EQ(ret, 0); int buflen = reactor_name(reactor, 0, 0); - char* buf = new char[buflen]; - reactor_name(reactor, buflen, buf); - string rName = buf; + vector buf(buflen); + reactor_name(reactor, buflen, buf.data()); + string rName(buf.data()); ASSERT_EQ(rName, "spam"); - delete[] buf; } vector T_ctreactor = {