77using System . IO ;
88using System . Text ;
99using NUnit . Framework ;
10+ using SIL . Core . ClearShare ;
1011using SIL . LCModel . Core . KernelInterfaces ;
1112using SIL . LCModel . Core . Text ;
1213using SIL . LCModel . Core . WritingSystems ;
@@ -28,7 +29,7 @@ public class CmPictureTests: MemoryOnlyBackendProviderRestoredForEachTestTestBas
2829 private MockFileOS m_fileOs ;
2930 private ICmPictureFactory m_pictureFactory ;
3031 private ICmPicture m_pict ;
31- private string m_internalPath = Path . DirectorySeparatorChar + Path . GetRandomFileName ( ) ;
32+ private string m_internalPath ;
3233 private CoreWritingSystemDefinition m_wsGerman ;
3334 private CoreWritingSystemDefinition m_wsSpanish ;
3435 #endregion
@@ -43,6 +44,10 @@ public override void FixtureSetup()
4344 base . FixtureSetup ( ) ;
4445 Cache . ServiceLocator . WritingSystemManager . GetOrSet ( "de" , out m_wsGerman ) ;
4546 Cache . ServiceLocator . WritingSystemManager . GetOrSet ( "es" , out m_wsSpanish ) ;
47+ // Initialize internalPath inside a temp folder
48+ // .jpg file extension is needed for the test CmPicture_GetCreatorAndLicenseForPicture
49+ string tempFolder = Path . GetTempPath ( ) ;
50+ m_internalPath = Path . Combine ( tempFolder , Guid . NewGuid ( ) . ToString ( ) + ".jpg" ) ;
4651 }
4752
4853 /// -------------------------------------------------------------------------------------
@@ -74,6 +79,8 @@ protected override void CreateTestData()
7479 public override void TestTearDown ( )
7580 {
7681 FileUtils . Manager . Reset ( ) ;
82+ if ( File . Exists ( m_internalPath ) )
83+ File . Delete ( m_internalPath ) ;
7784 base . TestTearDown ( ) ;
7885 }
7986
@@ -343,6 +350,25 @@ public void CmPicture_GetTextRepOfPicture()
343350 Assert . AreEqual ( "MyRef" , figParams [ 6 ] , "Picture reference should be exported." ) ;
344351 }
345352
353+ /// -------------------------------------------------------------------------------------
354+ /// <summary>
355+ /// Test ability to get creator and license of a picture.
356+ /// </summary>
357+ /// -------------------------------------------------------------------------------------
358+ [ Test ]
359+ public void CmPicture_GetCreatorAndLicenseForPicture ( )
360+ {
361+ // Copy the test image penguin.jpg from TestData to a temp file located at m_internalPath
362+ string penguinPath = Path . Combine ( TestDirectoryFinder . TestDataDirectory , "penguin.jpg" ) ;
363+ File . Copy ( penguinPath , m_internalPath , overwrite : true ) ;
364+
365+ MetadataCore metadata = new MetadataCore ( ) ;
366+ metadata . Creator = "test creator" ;
367+ metadata . CopyrightNotice = "test copyright" ;
368+ metadata . Write ( m_pict . PictureFileRA . AbsoluteInternalPath , false ) ;
369+ Assert . AreEqual ( "test creator" , ( ( CmPicture ) m_pict ) . CreatorTSS . ToString ( ) ) ;
370+ Assert . AreEqual ( "test copyright" , ( ( CmPicture ) m_pict ) . LicenseTSS . ToString ( ) ) ;
371+ }
346372 /// -------------------------------------------------------------------------------------
347373 /// <summary>
348374 /// Test ability to update the properties of a picture, given a file, folder, etc.
0 commit comments