| 21 | #define VTK_CREATE(type, name) vtkSmartPointer<type> name = vtkSmartPointer<type>::New() |
| 22 | |
| 23 | int TestSQLGraphReader(int argc, char* argv[]) |
| 24 | { |
| 25 | vtkIdType vertices = 10; |
| 26 | |
| 27 | // Create a SQLite in-memory database |
| 28 | VTK_CREATE(vtkSQLiteDatabase, database); |
| 29 | database->SetDatabaseFileName(":memory:"); |
| 30 | |
| 31 | bool ok = database->Open(""); |
| 32 | if (!ok) |
| 33 | { |
| 34 | std::cerr << "Could not open database!" << std::endl; |
| 35 | std::cerr << database->GetLastErrorText() << std::endl; |
| 36 | return 1; |
| 37 | } |
| 38 | |
| 39 | // Build a graph |
| 40 | vtkSmartPointer<vtkSQLQuery> q; |
| 41 | q.TakeReference(database->GetQueryInstance()); |
| 42 | std::ostringstream oss; |
| 43 | |
| 44 | q->SetQuery("DROP TABLE IF EXISTS vertices"); |
| 45 | q->Execute(); |
| 46 | |
| 47 | q->SetQuery("CREATE TABLE vertices (id INTEGER, x FLOAT, y FLOAT)"); |
| 48 | q->Execute(); |
| 49 | for (int i = 0; i < vertices; i++) |
| 50 | { |
| 51 | oss.str(""); |
| 52 | oss << "INSERT INTO vertices VALUES(" << i << ", " |
| 53 | << 0.5 * cos(i * 2.0 * vtkMath::Pi() / vertices) << ", " |
| 54 | << 0.5 * sin(i * 2.0 * vtkMath::Pi() / vertices) << ")" << std::endl; |
| 55 | q->SetQuery(oss.str().c_str()); |
| 56 | q->Execute(); |
| 57 | } |
| 58 | |
| 59 | q->SetQuery("DROP TABLE IF EXISTS edges"); |
| 60 | q->Execute(); |
| 61 | |
| 62 | q->SetQuery("CREATE TABLE edges (id INTEGER, source INTEGER, target INTEGER)"); |
| 63 | q->Execute(); |
| 64 | for (int i = 0; i < vertices; i++) |
| 65 | { |
| 66 | oss.str(""); |
| 67 | oss << "INSERT INTO edges VALUES(" << 2 * i + 0 << ", " << i << ", " << (i + 1) % vertices |
| 68 | << ")" << std::endl; |
| 69 | q->SetQuery(oss.str().c_str()); |
| 70 | q->Execute(); |
| 71 | oss.str(""); |
| 72 | oss << "INSERT INTO edges VALUES(" << 2 * i + 1 << ", " << (i + 3) % vertices << ", " << i |
| 73 | << ")" << std::endl; |
| 74 | q->SetQuery(oss.str().c_str()); |
| 75 | q->Execute(); |
| 76 | } |
| 77 | |
| 78 | // Set up graph reader |
| 79 | VTK_CREATE(vtkSQLGraphReader, reader); |
| 80 | vtkSmartPointer<vtkSQLQuery> edgeQuery; |
nothing calls this directly
no test coverage detected