@@ -155,4 +155,123 @@ TEST(CatalogCoverageTests, RaftApply) {
155155 catalog->apply (entry);
156156}
157157
158+ // ============= New Tests =============
159+
160+ /* *
161+ * @brief Tests basic table creation and retrieval by ID
162+ */
163+ TEST (CatalogCoverageTests, CreateAndGetTable) {
164+ auto catalog = Catalog::create ();
165+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 },
166+ {" name" , common::ValueType::TYPE_TEXT, 1 }};
167+
168+ oid_t tid = catalog->create_table (" users" , cols);
169+ ASSERT_NE (tid, 0 );
170+
171+ // Retrieve by ID
172+ auto table_opt = catalog->get_table (tid);
173+ ASSERT_TRUE (table_opt.has_value ());
174+ EXPECT_EQ ((*table_opt)->name , " users" );
175+ EXPECT_EQ ((*table_opt)->num_columns (), 2 );
176+ }
177+
178+ /* *
179+ * @brief Tests table creation and retrieval by name
180+ */
181+ TEST (CatalogCoverageTests, CreateAndGetTableByName) {
182+ auto catalog = Catalog::create ();
183+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
184+
185+ oid_t tid = catalog->create_table (" products" , cols);
186+ ASSERT_NE (tid, 0 );
187+
188+ // Retrieve by name
189+ auto table_opt = catalog->get_table_by_name (" products" );
190+ ASSERT_TRUE (table_opt.has_value ());
191+ EXPECT_EQ ((*table_opt)->table_id , tid);
192+ }
193+
194+ /* *
195+ * @brief Tests get_all_tables returns created tables
196+ */
197+ TEST (CatalogCoverageTests, GetAllTables) {
198+ auto catalog = Catalog::create ();
199+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
200+
201+ catalog->create_table (" table1" , cols);
202+ catalog->create_table (" table2" , cols);
203+ catalog->create_table (" table3" , cols);
204+
205+ auto tables = catalog->get_all_tables ();
206+ EXPECT_EQ (tables.size (), 3 );
207+ }
208+
209+ /* *
210+ * @brief Tests get_table_indexes returns created indexes
211+ */
212+ TEST (CatalogCoverageTests, GetTableIndexes) {
213+ auto catalog = Catalog::create ();
214+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
215+
216+ oid_t tid = catalog->create_table (" indexed_table" , cols);
217+ ASSERT_NE (tid, 0 );
218+
219+ catalog->create_index (" idx1" , tid, {0 }, IndexType::BTree, false );
220+ catalog->create_index (" idx2" , tid, {0 }, IndexType::Hash, true );
221+
222+ auto indexes = catalog->get_table_indexes (tid);
223+ EXPECT_EQ (indexes.size (), 2 );
224+ }
225+
226+ /* *
227+ * @brief Tests catalog save and load functionality
228+ *
229+ * Note: save() and load() are stubs that don't fully persist table data.
230+ * save() writes a header comment but no table data.
231+ * load() reads but doesn't parse table entries.
232+ */
233+ TEST (CatalogCoverageTests, SaveAndLoad) {
234+ auto catalog = Catalog::create ();
235+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
236+ catalog->create_table (" persisted_table" , cols);
237+
238+ // Save catalog - should succeed
239+ ASSERT_TRUE (catalog->save (" /tmp/test_catalog.bin" ));
240+
241+ // Create new catalog and load - should succeed (returns true)
242+ auto loaded_catalog = Catalog::create ();
243+ ASSERT_TRUE (loaded_catalog->load (" /tmp/test_catalog.bin" ));
244+
245+ // Note: Due to stub implementation, loaded catalog won't have the table
246+ // This test verifies the save/load cycle works without crashing
247+
248+ // Cleanup
249+ std::remove (" /tmp/test_catalog.bin" );
250+ }
251+
252+ /* *
253+ * @brief Tests version increments after catalog operations
254+ */
255+ TEST (CatalogCoverageTests, VersionIncrement) {
256+ auto catalog = Catalog::create ();
257+ uint64_t initial_version = catalog->get_version ();
258+
259+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
260+ catalog->create_table (" versioned_table" , cols);
261+
262+ EXPECT_GT (catalog->get_version (), initial_version);
263+ }
264+
265+ /* *
266+ * @brief Tests that print() doesn't crash
267+ */
268+ TEST (CatalogCoverageTests, PrintDoesNotCrash) {
269+ auto catalog = Catalog::create ();
270+ std::vector<ColumnInfo> cols = {{" id" , common::ValueType::TYPE_INT64, 0 }};
271+ catalog->create_table (" printed_table" , cols);
272+
273+ // Should not throw or crash
274+ EXPECT_NO_THROW (catalog->print ());
275+ }
276+
158277} // namespace
0 commit comments