const TCHAR *getValue() { return m_value; }
void setValue(const TCHAR *value) { safe_free(m_value); m_value = _tcsdup_ex(value); }
- void setPreallocatedValue(TCHAR *value) { safe_free(m_value); m_value = value; }
+ void setPreallocatedValue(TCHAR *value) { free(m_value); m_value = value; }
int getStatus() { return m_status; }
void setStatus(int status) { m_status = status; }
void setPreallocated(int index, TCHAR *value, int status, UINT32 objectId) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocated(value, status, objectId); }
void setValue(int index, const TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setValue(value); }
- void setPreallocatedValue(int index, TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocatedValue(value); }
+ void setPreallocatedValue(int index, TCHAR *value) { TableCell *c = m_cells->get(index); if (c != NULL) c->setPreallocatedValue(value); else free(value); }
void setStatus(int index, int status) { TableCell *c = m_cells->get(index); if (c != NULL) c->setStatus(status); }
/**
* Set pre-allocated data at position
*/
-void Table::setPreallocatedAt(int nRow, int nCol, TCHAR *pszData)
+void Table::setPreallocatedAt(int nRow, int nCol, TCHAR *data)
{
TableRow *r = m_data->get(nRow);
if (r != NULL)
{
- r->setPreallocatedValue(nCol, pszData);
+ r->setPreallocatedValue(nCol, data);
+ }
+ else
+ {
+ free(data);
}
}
delete array;
}
+/**
+ * Table tests
+ */
+static void TestTable()
+{
+ StartTest(_T("Table: create"));
+ Table *table = new Table();
+ AssertEquals(table->getNumRows(), 0);
+ EndTest();
+
+ StartTest(_T("Table: set on empty table"));
+ table->set(0, 1.0);
+ table->set(1, _T("test"));
+ table->setPreallocated(1, _tcsdup(_T("test")));
+ AssertEquals(table->getNumRows(), 0);
+ EndTest();
+
+ StartTest(_T("Table: add row"));
+ table->addRow();
+ AssertEquals(table->getNumRows(), 1);
+ AssertEquals(table->getNumColumns(), 0);
+ EndTest();
+
+ StartTest(_T("Table: set on empty row"));
+ table->set(0, _T("test"));
+ table->setPreallocated(1, _tcsdup(_T("test")));
+ AssertEquals(table->getNumRows(), 1);
+ AssertEquals(table->getNumColumns(), 0);
+ EndTest();
+}
+
/**
* main()
*/
TestQueue();
TestHashMap();
TestObjectArray();
+ TestTable();
return 0;
}