System.Data.SQLite
Check-in [ab52fdc3e8]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Enhance the .NET Compact Framework test app to allow custom SQL to be executed prior to running the tests.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ab52fdc3e88730e55f9f6463359de8769d228281
User & Date: mistachkin 2013-05-09 21:51:54
Context
2013-05-09
21:54
Fix minor typo in previous commit. check-in: ef6282a18c user: mistachkin tags: trunk
21:51
Enhance the .NET Compact Framework test app to allow custom SQL to be executed prior to running the tests. check-in: ab52fdc3e8 user: mistachkin tags: trunk
2013-05-05
02:28
Fixup HTML entity escapes in the contributor agreement. check-in: f6168a7941 user: mistachkin tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Setup/deployAndTestCe.eagle.

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    #       itself, the System.Data.SQLite managed assembly, the SQLite interop
    #       assembly, and the test application configuration file.
    #
    set fileNames [list [file join $managed_directory testce.exe] [file \
        join $managed_directory System.Data.SQLite.dll] [file join \
        $native_directory [appendArgs SQLite.Interop. [format %03d \
        [$assemblyName Version.Build]] .dll]] [file join $managed_directory \
        test.cfg]]
  }

  #
  # NOTE: Setup the directory on the target device where the application files
  #       should be deployed to.
  #
  if {![info exists device_directory]} then {







|







232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    #       itself, the System.Data.SQLite managed assembly, the SQLite interop
    #       assembly, and the test application configuration file.
    #
    set fileNames [list [file join $managed_directory testce.exe] [file \
        join $managed_directory System.Data.SQLite.dll] [file join \
        $native_directory [appendArgs SQLite.Interop. [format %03d \
        [$assemblyName Version.Build]] .dll]] [file join $managed_directory \
        test.cfg] [file join $managed_directory test.sql]]
  }

  #
  # NOTE: Setup the directory on the target device where the application files
  #       should be deployed to.
  #
  if {![info exists device_directory]} then {

Changes to testce/Program.cs.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
































87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 * 
 * Released to the public domain, use at your own risk!
 ********************************************************/

using System;
using System.Data.Common;
using System.Data.SQLite;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace test
{
  class Program
  {
    private static readonly string DefaultConnectionString =
        "Data Source={DataDirectory}\\test.db;Password=yVXL39etehPX;";

    internal static DbConnection NewConnection()
    {
        return new SQLiteConnection();
    }

    [MTAThread]
    static int Main(string[] args)
    {
      bool autoClose = false;
      int exitCode = 2; /* INCOMPLETE */
      Assembly assembly = Assembly.GetExecutingAssembly();
      AssemblyName assemblyName = assembly.GetName();
      string directory = Path.GetDirectoryName(assemblyName.CodeBase);

      if (args.Length > 0)
      {
          try { autoClose = bool.Parse(args[0]); } catch { }

      }

      try { File.Delete(directory + "\\test.db"); } catch { }


      SQLiteFunction.RegisterFunction(typeof(TestFunc));
      SQLiteFunction.RegisterFunction(typeof(MyCount));
      SQLiteFunction.RegisterFunction(typeof(MySequence));

      using (DbConnection cnn = NewConnection())
      {
        string connectionString = DefaultConnectionString;

        try
        {
          //
          // NOTE: Attempt to open the configuration file associated with
          //       this test executable.  It should contain *EXACTLY* one
          //       line, which will be the connection string to use for
          //       this test run.
          //
          using (StreamReader streamReader = File.OpenText(
              directory + "\\test.cfg"))
          {
            connectionString = streamReader.ReadToEnd().Trim();
          }
        }
        catch
        {
          // do nothing.
        }

        //
        // NOTE: If we are unable to obtain a valid connection string
        //       bail out now.
        //
        if (connectionString != null)
        {
          //
          // NOTE: Replace the "{DataDirectory}" token, if any, in the
          //       connection string with the actual directory this test
          //       assembly is executing from.
          //
          connectionString = connectionString.Replace(
            "{DataDirectory}", directory);

          cnn.ConnectionString = connectionString;
          cnn.Open();

































          TestCases tests = new TestCases(connectionString, cnn, autoClose);

          tests.Run();

          Application.Run(tests.frm);

          if (tests.Succeeded())
              exitCode = 0; /* SUCCESS */
          else
              exitCode = 1; /* FAILURE */
        }
      }

      return exitCode;
    }
  }
}



|












|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
>
|

|
>

|
|
|

|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|

|
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|

|

|

|
|
|
|
|
|

|
|
|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/********************************************************
 * ADO.NET 2.0 Data Provider for SQLite Version 3.X
 * Written by Robert Simpson (robert@blackcastlesoft.com)
 *
 * Released to the public domain, use at your own risk!
 ********************************************************/

using System;
using System.Data.Common;
using System.Data.SQLite;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

namespace test
{
    class Program
    {
        private static readonly string DefaultConnectionString =
            "Data Source={DataDirectory}\\test.db;Password=yVXL39etehPX;";

        internal static DbConnection NewConnection()
        {
            return new SQLiteConnection();
        }

        [MTAThread]
        static int Main(string[] args)
        {
            bool autoClose = false;
            int exitCode = 2; /* INCOMPLETE */
            Assembly assembly = Assembly.GetExecutingAssembly();
            AssemblyName assemblyName = assembly.GetName();
            string directory = Path.GetDirectoryName(assemblyName.CodeBase);

            if (args.Length > 0)
            {
                try { autoClose = bool.Parse(args[0]); }
                catch { }
            }

            try { File.Delete(directory + "\\test.db"); }
            catch { }

            SQLiteFunction.RegisterFunction(typeof(TestFunc));
            SQLiteFunction.RegisterFunction(typeof(MyCount));
            SQLiteFunction.RegisterFunction(typeof(MySequence));

            using (DbConnection cnn = NewConnection())
            {
                string connectionString = DefaultConnectionString;

                try
                {
                    //
                    // NOTE: Attempt to open the configuration file associated with
                    //       this test executable.  It should contain *EXACTLY* one
                    //       line, which will be the connection string to use for
                    //       this test run.
                    //
                    using (StreamReader streamReader = File.OpenText(
                        directory + "\\test.cfg"))
                    {
                        connectionString = streamReader.ReadToEnd().Trim();
                    }
                }
                catch
                {
                    // do nothing.
                }

                //
                // NOTE: If we are unable to obtain a valid connection string
                //       bail out now.
                //
                if (connectionString != null)
                {
                    //
                    // NOTE: Replace the "{DataDirectory}" token, if any, in the
                    //       connection string with the actual directory this test
                    //       assembly is executing from.
                    //
                    connectionString = connectionString.Replace(
                      "{DataDirectory}", directory);

                    cnn.ConnectionString = connectionString;
                    cnn.Open();

                    string sql = null;

                    try
                    {
                        //
                        // NOTE: Attempt to open the SQL file associated with this test
                        //       executable.  If present, it can contain SQL statements
                        //       to be executed against the new connection prior to the
                        //       tests running.
                        //
                        using (StreamReader streamReader = File.OpenText(
                            directory + "\\test.sql"))
                        {
                            sql = streamReader.ReadToEnd().Trim();
                        }
                    }
                    catch
                    {
                        // do nothing.
                    }

                    if (!String.IsNullOrEmpty(sql))
                    {
                        using (DbCommand command = cnn.CreateCommand())
                        {
                            command.CommandText = sql;

                            /* IGNORED */
                            command.ExecuteNonQuery(); /* throw */
                        }
                    }

                    TestCases tests = new TestCases(connectionString, cnn, sql, autoClose);

                    tests.Run();

                    Application.Run(tests.frm);

                    if (tests.Succeeded())
                        exitCode = 0; /* SUCCESS */
                    else
                        exitCode = 1; /* FAILURE */
                }
            }

            return exitCode;
        }
    }
}

Changes to testce/TestCases.cs.

72
73
74
75
76
77
78

79
80
81
82
83
84
85
86

87
88
89
90
91

92
93
94
95
96
97
98














99
100
101
102
103






104
105
106
107
108
109
110
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
...
600
601
602
603
604
605
606











607
608
609
610
611
612
613

  internal class TestCases
  {
    internal Form1 frm;

    private string connectionString;
    private DbConnection cnn;

    private bool autoClose;
    private int total;
    private int passed;
    private int failed;

    internal TestCases(
        string connectionString,
        DbConnection cnn,

        bool autoExit
        )
    {
        this.connectionString = connectionString;
        this.cnn = cnn;

        this.autoClose = autoExit;
    }

    internal bool Succeeded()
    {
        return (failed == 0) && (passed == total);
    }















    internal void Run()
    {
      frm = new Form1();
      frm.Show();







      Type type = cnn.GetType();
      frm.WriteLine("\r\nBeginning Test on " + type.ToString());

      SQLiteConnection cnn2 = cnn as SQLiteConnection;
      if (cnn2 != null)
      {
................................................................................
      catch (Exception) { frm.WriteLine("FAIL - BinaryInsert"); failed++; }

      total++;
      try { VerifyBinaryData(cnn); frm.WriteLine("SUCCESS - VerifyBinaryData"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - VerifyBinaryData"); failed++; }

      total++;
      try { LockTest(cnn); frm.WriteLine("SUCCESS - LockTest"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - LockTest"); failed++; }

      total++;
      try { ParameterizedInsertMissingParams(cnn); frm.WriteLine("FAIL - ParameterizedInsertMissingParams"); failed++; }
      catch (Exception) { frm.WriteLine("SUCCESS - ParameterizedInsertMissingParams"); passed++; }

      total++;
................................................................................
          if (b[1000] != 3) throw new ArgumentException();
          if (b[2000] != 4) throw new ArgumentException();
          if (b[3000] != 5) throw new ArgumentException();
        }
      }
    }

    internal static void LockTest(DbConnection cnn)
    {
      using (DbCommand cmd = cnn.CreateCommand())
      {
        cmd.CommandText = "SELECT Field6 FROM TestCase WHERE Field6 IS NOT NULL";
        byte[] b = new byte[4000];

        using (DbDataReader rd = cmd.ExecuteReader())
................................................................................
          if (b[100] != 2) throw new ArgumentException();
          if (b[1000] != 3) throw new ArgumentException();
          if (b[2000] != 4) throw new ArgumentException();
          if (b[3000] != 5) throw new ArgumentException();

          using (DbConnection clone = (DbConnection)((ICloneable)cnn).Clone())
          {











            using (DbCommand newcmd = clone.CreateCommand())
            {
              newcmd.CommandText = "DELETE FROM TestCase WHERE Field6 IS NULL";
              newcmd.CommandTimeout = 2;
              int cmdStart = Environment.TickCount;
              int cmdEnd;








>








>





>







>
>
>
>
>
>
>
>
>
>
>
>
>
>





>
>
>
>
>
>







 







|







 







|







 







>
>
>
>
>
>
>
>
>
>
>







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
...
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
...
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
...
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647

  internal class TestCases
  {
    internal Form1 frm;

    private string connectionString;
    private DbConnection cnn;
    private string sql;
    private bool autoClose;
    private int total;
    private int passed;
    private int failed;

    internal TestCases(
        string connectionString,
        DbConnection cnn,
        string sql,
        bool autoExit
        )
    {
        this.connectionString = connectionString;
        this.cnn = cnn;
        this.sql = sql;
        this.autoClose = autoExit;
    }

    internal bool Succeeded()
    {
        return (failed == 0) && (passed == total);
    }

    private static string FormatString(string value)
    {
        if (value == null)
            return "(null)";

        if (value.Length == 0)
            return "(empty)";

        if (value.Trim().Length == 0)
            return "(whitespace)";

        return value;
    }

    internal void Run()
    {
      frm = new Form1();
      frm.Show();

      frm.WriteLine(String.Format("\r\nTest connection string:\r\n\r\n{0}",
          FormatString(connectionString)));

      frm.WriteLine(String.Format("\r\nTest initialization SQL:\r\n\r\n{0}",
          FormatString(sql)));

      Type type = cnn.GetType();
      frm.WriteLine("\r\nBeginning Test on " + type.ToString());

      SQLiteConnection cnn2 = cnn as SQLiteConnection;
      if (cnn2 != null)
      {
................................................................................
      catch (Exception) { frm.WriteLine("FAIL - BinaryInsert"); failed++; }

      total++;
      try { VerifyBinaryData(cnn); frm.WriteLine("SUCCESS - VerifyBinaryData"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - VerifyBinaryData"); failed++; }

      total++;
      try { LockTest(cnn, sql); frm.WriteLine("SUCCESS - LockTest"); passed++; }
      catch (Exception) { frm.WriteLine("FAIL - LockTest"); failed++; }

      total++;
      try { ParameterizedInsertMissingParams(cnn); frm.WriteLine("FAIL - ParameterizedInsertMissingParams"); failed++; }
      catch (Exception) { frm.WriteLine("SUCCESS - ParameterizedInsertMissingParams"); passed++; }

      total++;
................................................................................
          if (b[1000] != 3) throw new ArgumentException();
          if (b[2000] != 4) throw new ArgumentException();
          if (b[3000] != 5) throw new ArgumentException();
        }
      }
    }

    internal static void LockTest(DbConnection cnn, string sql)
    {
      using (DbCommand cmd = cnn.CreateCommand())
      {
        cmd.CommandText = "SELECT Field6 FROM TestCase WHERE Field6 IS NOT NULL";
        byte[] b = new byte[4000];

        using (DbDataReader rd = cmd.ExecuteReader())
................................................................................
          if (b[100] != 2) throw new ArgumentException();
          if (b[1000] != 3) throw new ArgumentException();
          if (b[2000] != 4) throw new ArgumentException();
          if (b[3000] != 5) throw new ArgumentException();

          using (DbConnection clone = (DbConnection)((ICloneable)cnn).Clone())
          {
            if (sql != null)
            {
              using (DbCommand command = clone.CreateCommand())
              {
                command.CommandText = sql;

                /* IGNORED */
                command.ExecuteNonQuery(); /* throw */
              }
            }

            using (DbCommand newcmd = clone.CreateCommand())
            {
              newcmd.CommandText = "DELETE FROM TestCase WHERE Field6 IS NULL";
              newcmd.CommandTimeout = 2;
              int cmdStart = Environment.TickCount;
              int cmdEnd;

Added testce/test.sql.

Changes to testce/testce.2005.csproj.

91
92
93
94
95
96
97



98
99
100
101
102
103
104
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <Content Include="test.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>



  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2005.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2005</Name>
    </ProjectReference>
  </ItemGroup>







>
>
>







91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <Content Include="test.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="test.sql">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2005.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2005</Name>
    </ProjectReference>
  </ItemGroup>

Changes to testce/testce.2008.csproj.

92
93
94
95
96
97
98



99
100
101
102
103
104
105
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <Content Include="test.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>



  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2008.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2008</Name>
    </ProjectReference>
  </ItemGroup>







>
>
>







92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
      <SubType>Designer</SubType>
    </EmbeddedResource>
  </ItemGroup>
  <ItemGroup>
    <Content Include="test.cfg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
    <Content Include="test.sql">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\System.Data.SQLite\System.Data.SQLite.Compact.2008.csproj">
      <Project>{AC139951-261A-4463-B6FA-AEBC25283A66}</Project>
      <Name>System.Data.SQLite.Compact.2008</Name>
    </ProjectReference>
  </ItemGroup>