summaryrefslogtreecommitdiffstats
path: root/filter_test.go
diff options
context:
space:
mode:
authortmfkams <tmfkams@gmail.com>2014-01-19 23:04:16 +0100
committerSamuel Stauffer <samuel@descolada.com>2014-03-19 21:57:58 +0100
commite45f83457931e08f9f6d5aec48f51fd390a01eb8 (patch)
treed95a79f94932115bf5c0441f2eeb520959bbda0d /filter_test.go
parentMerge pull request #4 from bollenberger/master (diff)
downloadldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.gz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.bz2
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.lz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.xz
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.tar.zst
ldap-e45f83457931e08f9f6d5aec48f51fd390a01eb8.zip
Diffstat (limited to 'filter_test.go')
-rw-r--r--filter_test.go117
1 files changed, 58 insertions, 59 deletions
diff --git a/filter_test.go b/filter_test.go
index 4b403e4..c56a937 100644
--- a/filter_test.go
+++ b/filter_test.go
@@ -1,78 +1,77 @@
package ldap
import (
- "github.com/mmitton/asn1-ber"
- "testing"
+ "github.com/tmfkams/asn1-ber"
+ "testing"
)
type compile_test struct {
- filter_str string
- filter_type int
+ filter_str string
+ filter_type int
}
-
-var test_filters = []compile_test {
- compile_test{ filter_str: "(&(sn=Miller)(givenName=Bob))", filter_type: FilterAnd },
- compile_test{ filter_str: "(|(sn=Miller)(givenName=Bob))", filter_type: FilterOr },
- compile_test{ filter_str: "(!(sn=Miller))", filter_type: FilterNot },
- compile_test{ filter_str: "(sn=Miller)", filter_type: FilterEqualityMatch },
- compile_test{ filter_str: "(sn=Mill*)", filter_type: FilterSubstrings },
- compile_test{ filter_str: "(sn=*Mill)", filter_type: FilterSubstrings },
- compile_test{ filter_str: "(sn=*Mill*)", filter_type: FilterSubstrings },
- compile_test{ filter_str: "(sn>=Miller)", filter_type: FilterGreaterOrEqual },
- compile_test{ filter_str: "(sn<=Miller)", filter_type: FilterLessOrEqual },
- compile_test{ filter_str: "(sn=*)", filter_type: FilterPresent },
- compile_test{ filter_str: "(sn~=Miller)", filter_type: FilterApproxMatch },
- // compile_test{ filter_str: "()", filter_type: FilterExtensibleMatch },
+var test_filters = []compile_test{
+ compile_test{filter_str: "(&(sn=Miller)(givenName=Bob))", filter_type: FilterAnd},
+ compile_test{filter_str: "(|(sn=Miller)(givenName=Bob))", filter_type: FilterOr},
+ compile_test{filter_str: "(!(sn=Miller))", filter_type: FilterNot},
+ compile_test{filter_str: "(sn=Miller)", filter_type: FilterEqualityMatch},
+ compile_test{filter_str: "(sn=Mill*)", filter_type: FilterSubstrings},
+ compile_test{filter_str: "(sn=*Mill)", filter_type: FilterSubstrings},
+ compile_test{filter_str: "(sn=*Mill*)", filter_type: FilterSubstrings},
+ compile_test{filter_str: "(sn>=Miller)", filter_type: FilterGreaterOrEqual},
+ compile_test{filter_str: "(sn<=Miller)", filter_type: FilterLessOrEqual},
+ compile_test{filter_str: "(sn=*)", filter_type: FilterPresent},
+ compile_test{filter_str: "(sn~=Miller)", filter_type: FilterApproxMatch},
+ // compile_test{ filter_str: "()", filter_type: FilterExtensibleMatch },
}
-func TestFilter( t *testing.T ) {
- // Test Compiler and Decompiler
- for _, i := range test_filters {
- filter, err := CompileFilter( i.filter_str )
- if err != nil {
- t.Errorf( "Problem compiling %s - %s", err.String() )
- } else if filter.Tag != uint8(i.filter_type) {
- t.Errorf( "%q Expected %q got %q", i.filter_str, FilterMap[ uint64(i.filter_type) ], FilterMap[ uint64(filter.Tag) ] )
- } else {
- o, err := DecompileFilter( filter )
- if err != nil {
- t.Errorf( "Problem compiling %s - %s", i, err.String() )
- } else if i.filter_str != o {
- t.Errorf( "%q expected, got %q", i.filter_str, o )
- }
- }
- }
+func TestFilter(t *testing.T) {
+ // Test Compiler and Decompiler
+ for _, i := range test_filters {
+ filter, err := CompileFilter(i.filter_str)
+ if err != nil {
+ t.Errorf("Problem compiling %s - %s", err.String())
+ } else if filter.Tag != uint8(i.filter_type) {
+ t.Errorf("%q Expected %q got %q", i.filter_str, FilterMap[uint64(i.filter_type)], FilterMap[uint64(filter.Tag)])
+ } else {
+ o, err := DecompileFilter(filter)
+ if err != nil {
+ t.Errorf("Problem compiling %s - %s", i, err.String())
+ } else if i.filter_str != o {
+ t.Errorf("%q expected, got %q", i.filter_str, o)
+ }
+ }
+ }
}
-func BenchmarkFilterCompile( b *testing.B ) {
- b.StopTimer()
- filters := make([]string, len( test_filters ) )
+func BenchmarkFilterCompile(b *testing.B) {
+ b.StopTimer()
+ filters := make([]string, len(test_filters))
- // Test Compiler and Decompiler
- for idx, i := range test_filters {
- filters[ idx ] = i.filter_str
- }
+ // Test Compiler and Decompiler
+ for idx, i := range test_filters {
+ filters[idx] = i.filter_str
+ }
- max_idx := len( filters )
- b.StartTimer()
- for i := 0; i < b.N; i++ {
- CompileFilter( filters[ i % max_idx ] )
- }
+ max_idx := len(filters)
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ CompileFilter(filters[i%max_idx])
+ }
}
-func BenchmarkFilterDecompile( b *testing.B ) {
- b.StopTimer()
- filters := make([]*ber.Packet, len( test_filters ) )
+func BenchmarkFilterDecompile(b *testing.B) {
+ b.StopTimer()
+ filters := make([]*ber.Packet, len(test_filters))
- // Test Compiler and Decompiler
- for idx, i := range test_filters {
- filters[ idx ], _ = CompileFilter( i.filter_str )
- }
+ // Test Compiler and Decompiler
+ for idx, i := range test_filters {
+ filters[idx], _ = CompileFilter(i.filter_str)
+ }
- max_idx := len( filters )
- b.StartTimer()
- for i := 0; i < b.N; i++ {
- DecompileFilter( filters[ i % max_idx ] )
- }
+ max_idx := len(filters)
+ b.StartTimer()
+ for i := 0; i < b.N; i++ {
+ DecompileFilter(filters[i%max_idx])
+ }
}