aboutsummaryrefslogtreecommitdiff
path: root/rdfloader/parser2v2/parse_other_license_info_test.go
diff options
context:
space:
mode:
authorRishabh Bhatnagar <bhatnagarrishabh4@gmail.com>2020-08-30 23:01:21 +0530
committerRishabh Bhatnagar <bhatnagarrishabh4@gmail.com>2020-08-30 23:01:21 +0530
commit84fab30a66a136c293769b182265c62e6665b302 (patch)
treea907b98dd2d7b277f0fce5808f4e1acb6009720f /rdfloader/parser2v2/parse_other_license_info_test.go
parent054eb919a1867a7b0c171a8c6fcdc3140a7e2903 (diff)
downloadspdx-tools-84fab30a66a136c293769b182265c62e6665b302.tar.gz
Add Tests and Bug Fixes for Relationships and Licenses
- licenseTypes: renamed license of WithExceptionOperator to member - ignore rdf:type triple in Licenses - add comment to LicenseException Signed-off-by: Rishabh Bhatnagar <bhatnagarrishabh4@gmail.com>
Diffstat (limited to 'rdfloader/parser2v2/parse_other_license_info_test.go')
-rw-r--r--rdfloader/parser2v2/parse_other_license_info_test.go71
1 files changed, 71 insertions, 0 deletions
diff --git a/rdfloader/parser2v2/parse_other_license_info_test.go b/rdfloader/parser2v2/parse_other_license_info_test.go
new file mode 100644
index 0000000..286438e
--- /dev/null
+++ b/rdfloader/parser2v2/parse_other_license_info_test.go
@@ -0,0 +1,71 @@
+package parser2v2
+
+import (
+ gordfParser "github.com/RishabhBhatnagar/gordf/rdfloader/parser"
+ "reflect"
+ "testing"
+)
+
+func Test_rdfParser2_2_getExtractedLicensingInfoFromNode(t *testing.T) {
+ var parser *rdfParser2_2
+ var err error
+ var node *gordfParser.Node
+
+ // TestCase 1: invalid predicate must raise an error
+ parser, _ = parserFromBodyContent(`
+ <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware">
+ <spdx:licenseID>LicenseRef-Freeware</spdx:licenseID>
+ <spdx:name>freeware</spdx:name>
+ <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>
+ </spdx:ExtractedLicensingInfo>
+ `)
+ node = parser.gordfParserObj.Triples[0].Subject
+ _, err = parser.getExtractedLicensingInfoFromNode(node)
+ if err == nil {
+ t.Errorf("expected an error saying invalid predicate, got <nil>")
+ }
+
+ // TestCase 2: valid input
+ parser, _ = parserFromBodyContent(`
+ <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware">
+ <spdx:licenseId>LicenseRef-Freeware</spdx:licenseId>
+ <spdx:name>freeware</spdx:name>
+ <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>
+ </spdx:ExtractedLicensingInfo>
+ `)
+ node = parser.gordfParserObj.Triples[0].Subject
+ _, err = parser.getExtractedLicensingInfoFromNode(node)
+ if err != nil {
+ t.Errorf("unexpected error: %v", err)
+ }
+}
+
+func Test_rdfParser2_2_extractedLicenseToOtherLicense(t *testing.T) {
+ // nothing to test for this function.
+ parser, _ := parserFromBodyContent(`
+ <spdx:ExtractedLicensingInfo rdf:about="http://anupam-VirtualBox/repo/SPDX2_time-1.9.tar.gz_1535120734-spdx.rdf#LicenseRef-Freeware">
+ <spdx:licenseId>LicenseRef-Freeware</spdx:licenseId>
+ <spdx:name>freeware</spdx:name>
+ <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>
+ </spdx:ExtractedLicensingInfo>
+ `)
+ node := parser.gordfParserObj.Triples[0].Subject
+ extLicense, _ := parser.getExtractedLicensingInfoFromNode(node)
+ othLic := parser.extractedLicenseToOtherLicense(extLicense)
+
+ if othLic.LicenseIdentifier != extLicense.licenseID {
+ t.Errorf("expected %v, got %v", othLic.LicenseIdentifier, extLicense.licenseID)
+ }
+ if othLic.ExtractedText != extLicense.extractedText {
+ t.Errorf("expected %v, got %v", othLic.ExtractedText, extLicense.extractedText)
+ }
+ if othLic.LicenseComment != extLicense.comment {
+ t.Errorf("expected %v, got %v", othLic.LicenseComment, extLicense.comment)
+ }
+ if !reflect.DeepEqual(othLic.LicenseCrossReferences, extLicense.seeAlso) {
+ t.Errorf("expected %v, got %v", othLic.LicenseCrossReferences, extLicense.seeAlso)
+ }
+ if othLic.LicenseName != extLicense.name {
+ t.Errorf("expected %v, got %v", othLic.LicenseName, extLicense.name)
+ }
+}