Revert accidental checkin to NSS.
[wine-gecko.git] / layout / html / tests / CellMapTest / CellMapTest.cpp
blob622eaae706375aa380660c1804a1e9f85504faa3
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
24 * Alternatively, the contents of this file may be used under the terms of
25 * either of the GNU General Public License Version 2 or later (the "GPL"),
26 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #include <stdio.h>
38 #include "nscore.h"
39 #include "..\..\src\nsCellMap.h"
41 static FILE * out;
43 class CellData
45 public:
46 PRInt32 mID;
48 CellData(PRInt32 aID)
49 { mID = aID;};
53 class BasicTest
55 public:
56 BasicTest();
57 virtual ~BasicTest() {};
59 void DumpCellMap(nsCellMap *aMap, PRInt32 aRows, PRInt32 aCols);
60 void VerifyRowsAndCols(nsCellMap *aMap, PRInt32 aRows, PRInt32 aCols);
63 BasicTest::BasicTest()
65 PRInt32 rows = 3;
66 PRInt32 cols = 4;
67 nsCellMap *map = new nsCellMap(rows, cols);
68 fprintf(out, "\nCreating %d by %d table with these values...\n", rows, cols);
69 for (PRInt32 i=0; i<rows; i++)
71 for (PRInt32 j=0; j<cols; j++)
73 CellData * cellData = new CellData((i*cols)+j);
74 fprintf(out, "cell_%d ", cellData->mID);
75 map->SetCellAt(cellData, i, j);
77 fprintf(out, "\n");
79 // verify input
80 DumpCellMap(map, rows, cols);
81 VerifyRowsAndCols(map, rows, cols);
83 // cell map's own output should match above output
84 map->DumpCellMap();
86 // append a column
87 fprintf(out, "\nadding a column, so cols=%d\n", cols);
88 cols++;
89 map->GrowTo(cols);
90 DumpCellMap(map, rows, cols);
91 VerifyRowsAndCols(map, rows, cols);
93 // reset the map
94 rows++; cols++;
95 fprintf(out, "\nresetting the map to %d,%d\n", rows, cols);
96 map->Reset(rows, cols);
97 DumpCellMap(map, rows, cols);
98 VerifyRowsAndCols(map, rows, cols);
102 void BasicTest::DumpCellMap(nsCellMap *aMap, PRInt32 aRows, PRInt32 aCols)
104 fprintf(out, "\nPrinting out %d by %d table...\n", aRows, aCols);
105 for (PRInt32 i=0; i<aRows; i++)
107 for (PRInt32 j=0; j<aCols; j++)
109 CellData * cellData = aMap->GetCellAt(i, j);
110 if (nsnull!=cellData)
111 fprintf(out, "Cell_%d ", cellData->mID);
112 else
113 fprintf(out, "null ");
115 fprintf(out, "\n");
119 void BasicTest::VerifyRowsAndCols(nsCellMap *aMap, PRInt32 aRows, PRInt32 aCols)
121 if (aMap->GetRowCount()!=aRows)
122 fprintf(out, "ERROR: map->mRowCount!=rows, %d != %d\n", aMap->GetRowCount(), aRows);
123 if (aMap->GetColCount()!=aCols)
124 fprintf(out, "ERROR: map->mColCount!=cols, %d != %d\n", aMap->GetColCount(), aCols);
127 void main (int argc, char **argv)
129 out = fopen("CellMapTest.txt", "w+t");
130 if (nsnull==out)
132 printf("test failed to open output file\n");
133 exit(-1);
135 fprintf(out, "Test starting...\n\n");
136 BasicTest basicTest;
137 fprintf(out, "\nTest completed.\n");