Program: 76911
Project: 76911
Buggy source:
/** 
 * Test reloading a library. <p> 1) If library is reloaded, its element references are updated. <p> <strong>Case1:</strong> <p> Design.table1 -> lib1.libTable1 <p> The structure is synchronized with table in library. Local values of virtual elements are kept. <p> <strong>Case2:</strong> <p> lib1.theme1.style1 <p> If style is removed, the design can only find the style name, not style instance. <p> <strong>Case3:</strong> <p> name space <p> If the libTable1 drops 2 rows, Designl.table1 will not see these rows any more. And names of report elements in these rows are removed from the namespace. <p>
 * @throws Exception
 */
public void testReloadLibrary() throws Exception {
  openDesign("String_Node_Str");
  NameSpace ns=designHandle.getModule().getNameSpace(ReportDesign.ELEMENT_NAME_SPACE);
  assertEquals(7,ns.getCount());
  TableHandle table1=(TableHandle)designHandle.findElement("String_Node_Str");
  LabelHandle label1=(LabelHandle)designHandle.findElement("String_Node_Str");
  assertEquals(ColorPropertyType.RED,table1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.RED,label1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.RED,label1.getStringProperty(Style.COLOR_PROP));
  TableHandle parent=(TableHandle)table1.getExtends();
  assertNotNull(parent);
  RowHandle rowHandle=(RowHandle)table1.getHeader().get(0);
  CellHandle cellHandle=(CellHandle)rowHandle.getCells().get(0);
  assertEquals(cellHandle.getStringProperty(StyleHandle.COLOR_PROP),ColorPropertyType.BLUE);
  TableHandle table2=(TableHandle)designHandle.findElement("String_Node_Str");
  assertNotNull(table2.getExtends());
  assertEquals(table2.getStringProperty(StyleHandle.COLOR_PROP),ColorPropertyType.LIME);
  openLibrary("String_Node_Str");
  TableHandle libTable1=(TableHandle)libraryHandle.findElement("String_Node_Str");
  ((ThemeHandle)libraryHandle.getThemes().get(0)).getStyles().drop(0);
  libTable1.getDetail().drop(0);
  libTable1.getDetail().drop(0);
  assertEquals(0,libTable1.getDetail().getCount());
  TableHandle libTable2=(TableHandle)libraryHandle.findElement("String_Node_Str");
  libTable2.drop();
  libraryHandle.save();
  MyLibraryListener libraryListener=new MyLibraryListener();
  designHandle.addListener(libraryListener);
  designHandle.reloadLibrary(libraryHandle);
  assertEquals(1,libraryListener.events.size());
  assertTrue(libraryListener.events.get(0) instanceof LibraryReloadedEvent);
  assertEquals(3,ns.getCount());
  assertEquals(ColorPropertyType.BLACK,table1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.BLACK,label1.getStringProperty(Style.COLOR_PROP));
  assertNull(label1.getStyle());
  assertEquals("String_Node_Str",label1.getStringProperty(StyledElement.STYLE_PROP));
  assertEquals(0,table1.getDetail().getCount());
  assertEquals(1,table1.getHeader().getCount());
  assertFalse(designHandle.getCommandStack().canRedo());
  assertFalse(designHandle.getCommandStack().canUndo());
  recoverOriginalLibrary("String_Node_Str","String_Node_Str");
  save();
  compareTextFile("String_Node_Str");
}

Fixed version (ground truth):
/** 
 * Test reloading a library. <p> 1) If library is reloaded, its element references are updated. <p> <strong>Case1:</strong> <p> Design.table1 -> lib1.libTable1 <p> The structure is synchronized with table in library. Local values of virtual elements are kept. <p> <strong>Case2:</strong> <p> lib1.theme1.style1 <p> If style is removed, the design can only find the style name, not style instance. <p> <strong>Case3:</strong> <p> name space <p> If the libTable1 drops 2 rows, Designl.table1 will not see these rows any more. And names of report elements in these rows are removed from the namespace. <p>
 * @throws Exception
 */
public void testReloadLibrary() throws Exception {
  List fileNames=new ArrayList();
  fileNames.add(INPUT_FOLDER + "String_Node_Str");
  fileNames.add(INPUT_FOLDER + "String_Node_Str");
  List filePaths=dumpDesignAndLibrariesToFile(fileNames);
  String designFilePath=(String)filePaths.get(0);
  openDesign(designFilePath,false);
  NameSpace ns=designHandle.getModule().getNameSpace(ReportDesign.ELEMENT_NAME_SPACE);
  assertEquals(7,ns.getCount());
  TableHandle table1=(TableHandle)designHandle.findElement("String_Node_Str");
  LabelHandle label1=(LabelHandle)designHandle.findElement("String_Node_Str");
  assertEquals(ColorPropertyType.RED,table1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.RED,label1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.RED,label1.getStringProperty(Style.COLOR_PROP));
  TableHandle parent=(TableHandle)table1.getExtends();
  assertNotNull(parent);
  RowHandle rowHandle=(RowHandle)table1.getHeader().get(0);
  CellHandle cellHandle=(CellHandle)rowHandle.getCells().get(0);
  assertEquals(cellHandle.getStringProperty(StyleHandle.COLOR_PROP),ColorPropertyType.BLUE);
  TableHandle table2=(TableHandle)designHandle.findElement("String_Node_Str");
  assertNotNull(table2.getExtends());
  assertEquals(table2.getStringProperty(StyleHandle.COLOR_PROP),ColorPropertyType.LIME);
  String libFilePath=(String)filePaths.get(1);
  openLibrary(libFilePath,false);
  TableHandle libTable1=(TableHandle)libraryHandle.findElement("String_Node_Str");
  ((ThemeHandle)libraryHandle.getThemes().get(0)).getStyles().drop(0);
  libTable1.getDetail().drop(0);
  libTable1.getDetail().drop(0);
  assertEquals(0,libTable1.getDetail().getCount());
  TableHandle libTable2=(TableHandle)libraryHandle.findElement("String_Node_Str");
  libTable2.drop();
  libraryHandle.save();
  MyLibraryListener libraryListener=new MyLibraryListener();
  designHandle.addListener(libraryListener);
  designHandle.reloadLibrary(libraryHandle);
  assertEquals(1,libraryListener.events.size());
  assertTrue(libraryListener.events.get(0) instanceof LibraryReloadedEvent);
  assertEquals(3,ns.getCount());
  assertEquals(ColorPropertyType.BLACK,table1.getStringProperty(Style.COLOR_PROP));
  assertEquals(ColorPropertyType.BLACK,label1.getStringProperty(Style.COLOR_PROP));
  assertNull(label1.getStyle());
  assertEquals("String_Node_Str",label1.getStringProperty(StyledElement.STYLE_PROP));
  assertEquals(0,table1.getDetail().getCount());
  assertEquals(1,table1.getHeader().getCount());
  assertFalse(designHandle.getCommandStack().canRedo());
  assertFalse(designHandle.getCommandStack().canUndo());
  save();
  compareTextFile("String_Node_Str");
}