Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EverySpecialFeaturesOptInGiven #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions v2_parsed_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ func (p *V2ParsedConsent) PurposeAllowed(ps int) bool {
return true
}

// EverySpecialFeaturesOptInGiven returns true iff every feature number in specialFeatures exists in
// the V2ParsedConsent, otherwise false.
func (p *V2ParsedConsent) EverySpecialFeaturesOptInGiven(specialFeatures []int) bool {
for _, specialFeature := range specialFeatures {
if !p.SpecialFeaturesOptIn[specialFeature] {
return false
}
}
return true
}



// VendorAllowed returns true if the ParsedConsent contains affirmative consent
// for VendorID |v|.
func (p *V2ParsedConsent) VendorAllowed(v int) bool {
Expand Down
45 changes: 42 additions & 3 deletions v2_parsed_consent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,48 @@ func (p *V2ParsedConsentSuite) TestPurposeAllowed(c *check.C) {
}
}

func (v *V2ParsedConsentSuite) TestVendorAllowed(c *check.C) {
var tcs = []struct {
vendor int
func (v *V2ParsedConsentSuite) TestEverySpecialFeatureOptInGiven(c *check.C) {
var tcs = []struct{
specialFeatures []int
specialFeatureOptIn map[int]bool
exp bool
}{
{
specialFeatures: []int{1, 2, 3},
specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: true},
exp: true,
},
{
specialFeatures: []int{1, 2, 3},
specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: false},
exp: false,
},
{
specialFeatures: []int{1, 2, 3},
specialFeatureOptIn: map[int]bool{1: true, 2: true},
exp: false,
},
{
specialFeatures: []int{1, 2},
specialFeatureOptIn: map[int]bool{1: true, 2: true, 3: true},
exp: true,
},
}

for _, tc := range tcs {
c.Log(tc)

var pc = &iabconsent.V2ParsedConsent{
SpecialFeaturesOptIn: tc.specialFeatureOptIn,
}

c.Check(pc.EverySpecialFeaturesOptInGiven(tc.specialFeatures), check.Equals, tc.exp)
}
}

func (v *V2ParsedConsentSuite) TestVendorAllowed(c *check.C) {
var tcs = []struct{
vendor int
isRange bool
entries []*iabconsent.RangeEntry
vendors map[int]bool
Expand Down