<commit_before>// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, <NAME>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// See http://www.salome-platform.org/ or email : <EMAIL>
//

/*!
 * Check all methods of SALOMEDS_StudyManager
 * Use code of SALOMEDS_StudyManager.cxx
 */
void SALOMEDSTest::testStudyManager()
{
  //Create or find the Study manager
  _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );

  CPPUNIT_ASSERT(sm);

  //Check method NewStudy
  _PTR(Study) study1 = sm->NewStudy("Study1");
  CPPUNIT_ASSERT(study1);

  _PTR(Study) study2 = sm->NewStudy("Study2");
  CPPUNIT_ASSERT(study2);

  //Check method GetStudyByName
  _PTR(Study) study3 = sm->GetStudyByName("Study1");
  CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
  CPPUNIT_ASSERT(study3->Name() == study1->Name());

  //Check method GetStudyByName with empty name
  CPPUNIT_ASSERT(!sm->GetStudyByName(""));

  //Try to create Study with empty name
  _PTR(Study) study_empty = sm->NewStudy("");
  CPPUNIT_ASSERT(study_empty);
  CPPUNIT_ASSERT(sm->GetStudyByName(""));
  sm->Close(study_empty);

  //Check method FindStudyByID
  _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId());
  CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId());
  CPPUNIT_ASSERT(study4->Name() == study2->Name());

  //Check method GetOpenStudies
  std::vector<std::string> v = sm->GetOpenStudies();
  CPPUNIT_ASSERT(v.size() == 2);

  //Check method Close
  int id = study2->StudyId();
  sm->Close(study2);
  CPPUNIT_ASSERT(!sm->GetStudyByID(id));

  //Check method GetStudyByID for invalid ID
  CPPUNIT_ASSERT(!sm->GetStudyByID(-1));

  //Check methods CanPaste, CanCopy, Copy, Paste
  _PTR(StudyBuilder) sb1 = study1->NewBuilder();
  _PTR(SComponent) sco1 = sb1->NewComponent("Test");
  _PTR(SObject) so1 = sb1->NewObject(sco1);
  _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
  CPPUNIT_ASSERT(na1);
  na1->SetValue("Some name");

  CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
  
  CPPUNIT_ASSERT(sm->Copy(so1));

  CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR

  _PTR(SObject) so1_2 = sb1->NewObject(sco1);
  _PTR(SObject) pasted_so = sm->Paste(so1_2);
  CPPUNIT_ASSERT(pasted_so);

  _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
  CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");


  //Check method SaveAs
  sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
  std::string url = study1->URL();
  sm->Close(study1);

  //Check method Open
  _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf");  //Contains Test component
  system("rm -f srn_UnitTest_Save.hdf");
  url = study1->URL();
  CPPUNIT_ASSERT(study1_opened);
  CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");

  //Check method Save
  _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
  _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
  CPPUNIT_ASSERT(sco3);
  //   Add a new SObject with AttributeName that contains "Saved study" string
  _PTR(SObject) so3 = sb3->NewObject(sco3);
  std::string soID = so3->GetID();
  _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
  CPPUNIT_ASSERT(na3);
 
  na3->SetValue("Saved study");
<commit_msg>Fix bug in SALOMEDSTest_StudyManager<commit_after>// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
//
// See http://www.salome-platform.org/ or email : <EMAIL>
//

/*!
 * Check all methods of SALOMEDS_StudyManager
 * Use code of SALOMEDS_StudyManager.cxx
 */
void SALOMEDSTest::testStudyManager()
{
  //Create or find the Study manager
  _PTR(StudyManager) sm ( new SALOMEDS_StudyManager(_sm) );

  CPPUNIT_ASSERT(sm);

  //Check method NewStudy
  _PTR(Study) study1 = sm->NewStudy("Study1");
  CPPUNIT_ASSERT(study1);

  _PTR(Study) study2 = sm->NewStudy("Study2");
  CPPUNIT_ASSERT(study2);

  //Check method GetStudyByName
  _PTR(Study) study3 = sm->GetStudyByName("Study1");
  CPPUNIT_ASSERT(study3->StudyId() == study1->StudyId());
  CPPUNIT_ASSERT(study3->Name() == study1->Name());

  //Check method GetStudyByName with empty name
  CPPUNIT_ASSERT(!sm->GetStudyByName(""));

  //Try to create Study with empty name
  _PTR(Study) study_empty = sm->NewStudy("");
  CPPUNIT_ASSERT(study_empty);
  CPPUNIT_ASSERT(sm->GetStudyByName(""));
  sm->Close(study_empty);

  //Check method FindStudyByID
  _PTR(Study) study4 = sm->GetStudyByID(study2->StudyId());
  CPPUNIT_ASSERT(study4->StudyId() == study2->StudyId());
  CPPUNIT_ASSERT(study4->Name() == study2->Name());

  //Check method GetOpenStudies
  std::vector<std::string> v = sm->GetOpenStudies();
  CPPUNIT_ASSERT(v.size() == 2);

  //Check method Close
  int id = study2->StudyId();
  sm->Close(study2);
  CPPUNIT_ASSERT(!sm->GetStudyByID(id));

  //Check method GetStudyByID for invalid ID
  CPPUNIT_ASSERT(!sm->GetStudyByID(-1));

  //Check methods CanPaste, CanCopy, Copy, Paste
  _PTR(StudyBuilder) sb1 = study1->NewBuilder();
  _PTR(SComponent) sco1 = sb1->NewComponent("Test");
  _PTR(SObject) so1 = sb1->NewObject(sco1);
  _PTR(AttributeName) na1 = sb1->FindOrCreateAttribute(so1, "AttributeName");
  CPPUNIT_ASSERT(na1);
  na1->SetValue("Some name");

  CPPUNIT_ASSERT(!sm->CanCopy(so1)); //The father component has no IOR
  
  CPPUNIT_ASSERT(sm->Copy(so1));

  CPPUNIT_ASSERT(!sm->CanPaste(so1)); //The father component has no IOR

  _PTR(SObject) so1_2 = sb1->NewObject(sco1);
  _PTR(SObject) pasted_so = sm->Paste(so1_2);
  CPPUNIT_ASSERT(pasted_so);

  _PTR(AttributeName) na2 = sb1->FindOrCreateAttribute(pasted_so, "AttributeName");
  CPPUNIT_ASSERT(na2 && na2->Value() == "Some name");


  //Check method SaveAs
  sm->SaveAs("srn_UnitTest_Save.hdf", study1, false);
  std::string url = study1->URL();
  sm->Close(study1);

  //Check method Open
  _PTR(Study) study1_opened = sm->Open("srn_UnitTest_Save.hdf");  //Contains Test component
  system("rm -f srn_UnitTest_Save.hdf");
  url = study1_opened->URL();
  CPPUNIT_ASSERT(study1_opened);
  CPPUNIT_ASSERT(url == "srn_UnitTest_Save.hdf");

  //Check method Save
  _PTR(StudyBuilder) sb3 = study1_opened->NewBuilder();
  _PTR(SComponent) sco3 = study1_opened->FindComponent("Test");
  CPPUNIT_ASSERT(sco3);
  //   Add a new SObject with AttributeName that contains "Saved study" string
  _PTR(SObject) so3 = sb3->NewObject(sco3);
  std::string soID = so3->GetID();
  _PTR(AttributeName) na3 = sb3->FindOrCreateAttribute(so3, "AttributeName");
  CPPUNIT_ASSERT(na3);
 
  na3->SetValue("Saved study");

{'fraction_non_alphanumeric': 0.14096592302034813, 'fraction_numerical': 0.024515812699190977, 'mean_word_length': 4.561690524880709, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 98, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6880882', 'n_tokens_mistral': 3029, 'n_tokens_neox': 2761, 'n_words': 712}