nsAutoString buf; listBox->GetItemAt(buf, i); char * str = buf.ToNewCString();
nsAutoString buf2; listBox->GetItemAt(buf2, i); char * str = buf2.ToNewCString();
void listSelfTest(FILE * fd, char * aTitle, nsIListWidget * listBox) {  fprintf(fd, "\n\n-----------------------------\n");  fprintf(fd, "%s self test\n", aTitle);  fprintf(fd, "-----------------------------\n\n");  int inx = 4;  char * item4 = "List Item 4";  fprintf(fd, "\nTesting GetItemCount\n\tItem count should be [%d] is [%d] Test: [%s]\n", NUM_COMBOBOX_ITEMS, listBox->GetItemCount(),    (NUM_COMBOBOX_ITEMS == (int)listBox->GetItemCount()?"PASSED":"FAILED"));   fflush(fd);  fprintf(fd, "\nTesting SelectItem value is [%d]\n", inx); fflush(fd);  listBox->SelectItem(inx);  nsAutoString buf;  listBox->GetSelectedItem(buf);  char * selStr = buf.ToNewCString();  fprintf(fd, "\nTesting GetSelectedItem\n");  fprintf(fd, "\tSelection should be [%s] is [%s]  Test: [%s]\n",           item4, selStr, eval(!strcmp(item4, selStr))); fflush(fd);  if (nsnull != selStr) delete[] selStr;  int    sel    = listBox->GetSelectedIndex();  fprintf(fd, "\nTesting GetSelectedIndex\n");fflush(fd);  fprintf(fd, "\tSelection should be [%d] is [%d]  Test: [%s]\n",           inx, sel, eval(inx == (int)sel)); fflush(fd);  nsString item4Str(item4);  sel = listBox->FindItem(item4Str, 0);  fprintf(fd, "\nTesting FindItem\n");fflush(fd);  fprintf(fd, "\tItem index should be [%d] index is [%d] Test: [%s]\n",           inx, sel, eval(inx == (int)sel)); fflush(fd);  listBox->GetItemAt(buf, 4);  selStr = buf.ToNewCString();  fprintf(fd, "\nTesting GetItemAt\n\tItem %d should be [%s] is [%s]  Test: [%s]\n", inx, item4, selStr, eval(strcmp(selStr, item4) == 0)); fflush(fd);  if (nsnull != selStr) delete[] selStr;  listBox->SelectItem(2);  inx = listBox->GetSelectedIndex();  fprintf(fd, "\nTesting SelectItem && GetSelectedIndex\n\t Selected Item should be [%d] is [%d]  Test: [%s]\n", 2, inx, eval(inx == 2)); fflush(fd);  int i;  for (i=0;i<(int)listBox->GetItemCount();i++) {    nsAutoString buf;    listBox->GetItemAt(buf, i);    char * str = buf.ToNewCString();    fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);    if (nsnull != str) delete[] str;  }  fprintf(fd, "Removing Item #4\n");fflush(fd);  listBox->RemoveItemAt(4);    nsString item4string(item4);  fprintf(fd, "\nTesting RemoveItemAt\n\tTest: [%s]\n", eval(-1 == (int)listBox->FindItem(item4string, 0))); fflush(fd);  for (i=0;i<(int)listBox->GetItemCount();i++) {    nsAutoString buf;    listBox->GetItemAt(buf, i);    char * str = buf.ToNewCString();    fprintf(fd, "Item %d [%s]\n", i, str);fflush(fd);    if (nsnull != str) delete[] str;  }  listBox->Deselect();  fprintf(fd, "\nTesting Deselect\n\t Selected Item [%d]  Test:[%s]\n", (int)listBox->GetSelectedIndex(), (-1 == (int)listBox->GetSelectedIndex()?"PASSED":"FAILED")); fflush(fd);}