1// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 2 3package parser2v3 4 5import ( 6 "reflect" 7 "testing" 8 9 gordfParser "github.com/spdx/gordf/rdfloader/parser" 10) 11 12func Test_rdfParser2_3_getExtractedLicensingInfoFromNode(t *testing.T) { 13 var parser *rdfParser2_3 14 var err error 15 var node *gordfParser.Node 16 17 // TestCase 1: invalid predicate must raise an error 18 parser, _ = parserFromBodyContent(` 19 <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware"> 20 <spdx:licenseID>LicenseRef-Freeware</spdx:licenseID> 21 <spdx:name>freeware</spdx:name> 22 <spdx:extractedText><![CDATA[Software classified as freeware is licensed at no cost and is either fully functional for an unlimited time; or has only basic functions enabled with a fully functional version available commercially or as shareware.[8] In contrast to free software, the author usually restricts one or more rights of the user, including the rights to use, copy, distribute, modify and make derivative works of the software or extract the source code.[1][2][9][10] The software license may impose various additional restrictions on the type of use, e.g. only for personal use, private use, individual use, non-profit use, non-commercial use, academic use, educational use, use in charity or humanitarian organizations, non-military use, use by public authorities or various other combinations of these type of restrictions.[11] For instance, the license may be "free for private, non-commercial use". The software license may also impose various other restrictions, such as restricted use over a network, restricted use on a server, restricted use in a combination with some types of other software or with some hardware devices, prohibited distribution over the Internet other than linking to author's website, restricted distribution without author's consent, restricted number of copies, etc.]]></spdx:extractedText> 23 </spdx:ExtractedLicensingInfo> 24 `) 25 node = parser.gordfParserObj.Triples[0].Subject 26 _, err = parser.getExtractedLicensingInfoFromNode(node) 27 if err == nil { 28 t.Errorf("expected an error saying invalid predicate, got <nil>") 29 } 30 31 // TestCase 2: valid input 32 parser, _ = parserFromBodyContent(` 33 <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware"> 34 <spdx:licenseId>LicenseRef-Freeware</spdx:licenseId> 35 <spdx:name>freeware</spdx:name> 36 <spdx:extractedText><![CDATA[Software classified as freeware is licensed at no cost and is either fully functional for an unlimited time; or has only basic functions enabled with a fully functional version available commercially or as shareware.[8] In contrast to free software, the author usually restricts one or more rights of the user, including the rights to use, copy, distribute, modify and make derivative works of the software or extract the source code.[1][2][9][10] The software license may impose various additional restrictions on the type of use, e.g. only for personal use, private use, individual use, non-profit use, non-commercial use, academic use, educational use, use in charity or humanitarian organizations, non-military use, use by public authorities or various other combinations of these type of restrictions.[11] For instance, the license may be "free for private, non-commercial use". The software license may also impose various other restrictions, such as restricted use over a network, restricted use on a server, restricted use in a combination with some types of other software or with some hardware devices, prohibited distribution over the Internet other than linking to author's website, restricted distribution without author's consent, restricted number of copies, etc.]]></spdx:extractedText> 37 </spdx:ExtractedLicensingInfo> 38 `) 39 node = parser.gordfParserObj.Triples[0].Subject 40 _, err = parser.getExtractedLicensingInfoFromNode(node) 41 if err != nil { 42 t.Errorf("unexpected error: %v", err) 43 } 44} 45 46func Test_rdfParser2_3_extractedLicenseToOtherLicense(t *testing.T) { 47 // nothing to test for this function. 48 parser, _ := parserFromBodyContent(` 49 <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware"> 50 <spdx:licenseId>LicenseRef-Freeware</spdx:licenseId> 51 <spdx:name>freeware</spdx:name> 52 <spdx:extractedText><![CDATA[Software classified as freeware is licensed at no cost and is either fully functional for an unlimited time; or has only basic functions enabled with a fully functional version available commercially or as shareware.[8] In contrast to free software, the author usually restricts one or more rights of the user, including the rights to use, copy, distribute, modify and make derivative works of the software or extract the source code.[1][2][9][10] The software license may impose various additional restrictions on the type of use, e.g. only for personal use, private use, individual use, non-profit use, non-commercial use, academic use, educational use, use in charity or humanitarian organizations, non-military use, use by public authorities or various other combinations of these type of restrictions.[11] For instance, the license may be "free for private, non-commercial use". The software license may also impose various other restrictions, such as restricted use over a network, restricted use on a server, restricted use in a combination with some types of other software or with some hardware devices, prohibited distribution over the Internet other than linking to author's website, restricted distribution without author's consent, restricted number of copies, etc.]]></spdx:extractedText> 53 </spdx:ExtractedLicensingInfo> 54 `) 55 node := parser.gordfParserObj.Triples[0].Subject 56 extLicense, _ := parser.getExtractedLicensingInfoFromNode(node) 57 othLic := parser.extractedLicenseToOtherLicense(extLicense) 58 59 if othLic.LicenseIdentifier != extLicense.licenseID { 60 t.Errorf("expected %v, got %v", othLic.LicenseIdentifier, extLicense.licenseID) 61 } 62 if othLic.ExtractedText != extLicense.extractedText { 63 t.Errorf("expected %v, got %v", othLic.ExtractedText, extLicense.extractedText) 64 } 65 if othLic.LicenseComment != extLicense.comment { 66 t.Errorf("expected %v, got %v", othLic.LicenseComment, extLicense.comment) 67 } 68 if !reflect.DeepEqual(othLic.LicenseCrossReferences, extLicense.seeAlso) { 69 t.Errorf("expected %v, got %v", othLic.LicenseCrossReferences, extLicense.seeAlso) 70 } 71 if othLic.LicenseName != extLicense.name { 72 t.Errorf("expected %v, got %v", othLic.LicenseName, extLicense.name) 73 } 74} 75