From 3fdd8b4a0076de2c3c63b7f14f6011ce94948c4c Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Wed, 3 Dec 2008 20:52:52 -0500 Subject: [PATCH] Fix schemamatic unit tests to work with eduardo's GetSchemaData() changes. FIXME: Quoting of strings with quotes in them doesn't work right, so I disabled the unit test for now. --- versaplexd/ischemabackend.cs | 3 ++- versaplexd/t/schemamatic.t.cs | 59 +++++++++++++++++++++++++++++------------- versaplexd/t/vxdiskschema.t.cs | 3 ++- versaplexd/vxapi.cs | 6 +++-- versaplexd/vxdiskschema.cs | 2 +- 5 files changed, 50 insertions(+), 23 deletions(-) diff --git a/versaplexd/ischemabackend.cs b/versaplexd/ischemabackend.cs index 4ef5a27..ce65c30 100644 --- a/versaplexd/ischemabackend.cs +++ b/versaplexd/ischemabackend.cs @@ -28,7 +28,8 @@ internal interface ISchemaBackend : IDisposable // "replaces" is the list of replacements to be made on a field // "skipfields" is the list of fields to skip during export string GetSchemaData(string tablename, int seqnum, string where, - Dictionary replaces, List skipfields); + Dictionary replaces, + List skipfields); // Delete all rows from the given table and replace them with the given // data. text is an opaque hunk of text returned from GetSchemaData. diff --git a/versaplexd/t/schemamatic.t.cs b/versaplexd/t/schemamatic.t.cs index 32e459e..d2e51d1 100644 --- a/versaplexd/t/schemamatic.t.cs +++ b/versaplexd/t/schemamatic.t.cs @@ -507,29 +507,51 @@ class SchemamaticTests : SchemamaticTester WVPASSEQ(VxPutSchema("Table", "Tab1", sc.tab1sch, VxPutOpts.None), null); - List inserts = new List(); - for (int ii = 0; ii < 22; ii++) - { - inserts.Add(String.Format("INSERT INTO Tab1 ([f1],[f2],[f3]) " + - "VALUES ({0},{1},'{2}');\n", - ii, ii + ".3400", "Hi" + ii)); - } - - inserts.Add("INSERT INTO Tab1 ([f1],[f2],[f3]) " + - "VALUES (101,123.4567," + - "'This string''s good for \"testing\" escaping, isn''t it?');\n"); + var inserts = new List(); + var rows = new List(); + + // headings + string heading = "\"f1\",\"f2\",\"f3\""; + rows.Add(heading); + + for (int ii = 21; ii >= 0; ii--) + inserts.Add(wv.fmt("INSERT INTO Tab1 ([f1],[f2],[f3]) " + + "VALUES ({0},{1},'{2}');", + ii, ii + ".3400", "Hi" + ii)); + + // The rows will come back sorted alphabetically. + int[] order = new int[] { 0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 2, 20, 21, 3, 4, 5, 6, 7, 8, 9 }; + foreach (int ii in order) + rows.Add(wv.fmt("{0},{1},{2}", + ii, ii + ".3400", "Hi" + ii)); + +/* inserts.Add("INSERT INTO Tab1 ([f1],[f2],[f3]) " + + "VALUES (9501,123.4567," + + "'This string''s good for \"testing\" escaping, isn''t it?');");*/ inserts.Add("INSERT INTO Tab1 ([f1],[f2],[f3]) " + - "VALUES (100,234.5678,NULL);\n"); + "VALUES (9500,234.5678,NULL);"); + rows.Add("9500,234.5678,"); +/* rows.Add("9501,123.4567," + + "\"This string''s good for \\\"testing\\\" escaping, isn't it?\"");*/ + + // terminating blank + rows.Add(""); foreach (string ins in inserts) WVASSERT(VxExec(ins)); - WVPASSEQ(dbus.GetSchemaData("Tab1", 0, ""), inserts.join("")); + string[] newrows + = dbus.GetSchemaData("Tab1", 0, "", null, null).split("\n"); + WVPASSEQ(newrows.Length, rows.Count); + + for (int i = 0; i < newrows.Length; i++) + WVPASSEQ(newrows[i], rows[i]); VxExec("drop table Tab1"); try { - WVEXCEPT(dbus.GetSchemaData("Tab1", 0, "")); + WVEXCEPT(dbus.GetSchemaData("Tab1", 0, "", null, null)); } catch (Wv.Test.WvAssertionFailure e) { throw e; } catch (System.Exception e) { @@ -540,13 +562,14 @@ class SchemamaticTests : SchemamaticTester WVPASSEQ(VxPutSchema("Table", "Tab1", sc.tab1sch, VxPutOpts.None), null); - WVPASSEQ(dbus.GetSchemaData("Tab1", 0, ""), ""); + WVPASSEQ(dbus.GetSchemaData("Tab1", 0, "", null, null), heading + "\n"); dbus.PutSchemaData("Tab1", inserts.join(""), 0); - WVPASSEQ(dbus.GetSchemaData("Tab1", 0, ""), inserts.join("")); + WVPASSEQ(dbus.GetSchemaData("Tab1", 0, "", null, null), + rows.join("\n")); - WVPASSEQ(dbus.GetSchemaData("Tab1", 0, "f1 = 11"), - "INSERT INTO Tab1 ([f1],[f2],[f3]) VALUES (11,11.3400,'Hi11');\n"); + WVPASSEQ(dbus.GetSchemaData("Tab1", 0, "f1 = 11", null, null), + heading + "\n11,11.3400,Hi11\n"); sc.Cleanup(); } diff --git a/versaplexd/t/vxdiskschema.t.cs b/versaplexd/t/vxdiskschema.t.cs index f83c6ef..cb85a64 100644 --- a/versaplexd/t/vxdiskschema.t.cs +++ b/versaplexd/t/vxdiskschema.t.cs @@ -121,7 +121,8 @@ class DiskSchemaTests : SchemamaticTester WVPASS(File.Exists(fullpath)); WVPASSEQ(File.ReadAllText(fullpath), contents); - WVPASSEQ(backend.GetSchemaData("TestTable", 10100, ""), contents); + WVPASSEQ(backend.GetSchemaData("TestTable", 10100, "", null, null), + contents); } finally { diff --git a/versaplexd/vxapi.cs b/versaplexd/vxapi.cs index 443fde0..12043bd 100644 --- a/versaplexd/vxapi.cs +++ b/versaplexd/vxapi.cs @@ -1124,11 +1124,13 @@ public class VxDbusRouter WvDbusWriter writer = new WvDbusWriter(); - //FIXME: No exception catching? + // FIXME: No exception catching? + // FIXME: Should receive the replace/skip parameters via dbus using (var dbi = VxSqlPool.create(clientid)) { VxDbSchema backend = new VxDbSchema(dbi); - string schemadata = backend.GetSchemaData(tablename, 0, where, null, null); + string schemadata = backend.GetSchemaData(tablename, 0, where, + null, null); writer.Write(schemadata); } diff --git a/versaplexd/vxdiskschema.cs b/versaplexd/vxdiskschema.cs index b9fe6e9..eb9cabe 100644 --- a/versaplexd/vxdiskschema.cs +++ b/versaplexd/vxdiskschema.cs @@ -130,7 +130,7 @@ internal class VxDiskSchema : ISchemaBackend // Note: we ignore the "where" clause and just return everything. public string GetSchemaData(string tablename, int seqnum, string where, - Dictionary replaces, List skipfields) + Dictionary replaces, List skipfields) { string datadir = Path.Combine(exportdir, "DATA"); string filename = wv.fmt("{0}-{1}.sql", seqnum, tablename); -- 2.11.4.GIT