github.com/cellofellow/gopkg@v0.0.0-20140722061823-eec0544a62ad/database/leveldb.chai2010/options_test.go (about)

     1  // Copyright 2013 <chaishushan{AT}gmail.com>. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package leveldb
     6  
     7  import (
     8  	"testing"
     9  )
    10  
    11  func TestOptions(t *testing.T) {
    12  	//
    13  }
    14  
    15  func TestOptionsDefault(t *testing.T) {
    16  	//
    17  }
    18  
    19  func TestReadOptions_leveldb_options_t(t *testing.T) {
    20  	//
    21  }
    22  
    23  func TestReadOptions_leveldb_options_t_convert(t *testing.T) {
    24  	//
    25  }
    26  
    27  func TestReadOptions(t *testing.T) {
    28  	opt := &ReadOptions{}
    29  	if v := opt.HasFlag(RFVerifyChecksums); v != false {
    30  		t.Fatalf("expect = false, got = %v", v)
    31  	}
    32  	if v := opt.HasFlag(RFDontFillCache); v != false {
    33  		t.Fatalf("expect = false, got = %v", v)
    34  	}
    35  
    36  	opt.SetFlag(RFVerifyChecksums)
    37  	if v := opt.HasFlag(RFVerifyChecksums); v != true {
    38  		t.Fatalf("expect = true, got = %v", v)
    39  	}
    40  	if v := opt.HasFlag(RFDontFillCache); v != false {
    41  		t.Fatalf("expect = false, got = %v", v)
    42  	}
    43  
    44  	opt.SetFlag(RFDontFillCache)
    45  	if v := opt.HasFlag(RFVerifyChecksums); v != true {
    46  		t.Fatalf("expect = true, got = %v", v)
    47  	}
    48  	if v := opt.HasFlag(RFDontFillCache); v != true {
    49  		t.Fatalf("expect = true, got = %v", v)
    50  	}
    51  
    52  	opt.ClearFlag(RFVerifyChecksums)
    53  	if v := opt.HasFlag(RFVerifyChecksums); v != false {
    54  		t.Fatalf("expect = false, got = %v", v)
    55  	}
    56  	if v := opt.HasFlag(RFDontFillCache); v != true {
    57  		t.Fatalf("expect = true, got = %v", v)
    58  	}
    59  
    60  	opt.ClearFlag(RFDontFillCache)
    61  	if v := opt.HasFlag(RFVerifyChecksums); v != false {
    62  		t.Fatalf("expect = false, got = %v", v)
    63  	}
    64  	if v := opt.HasFlag(RFDontFillCache); v != false {
    65  		t.Fatalf("expect = false, got = %v", v)
    66  	}
    67  }
    68  
    69  func TestReadOptions_leveldb_readoptions_t(t *testing.T) {
    70  	opt := leveldb_readoptions_create()
    71  	defer leveldb_readoptions_destroy(opt)
    72  
    73  	if v := leveldb_readoptions_get_verify_checksums(opt); v != false {
    74  		t.Fatalf("expect = false, got = %v", v)
    75  	}
    76  	if v := leveldb_readoptions_get_fill_cache(opt); v != true {
    77  		t.Fatalf("expect = true, got = %v", v)
    78  	}
    79  
    80  	leveldb_readoptions_set_verify_checksums(opt, true)
    81  	if v := leveldb_readoptions_get_verify_checksums(opt); v != true {
    82  		t.Fatalf("expect = true, got = %v", v)
    83  	}
    84  
    85  	leveldb_readoptions_set_fill_cache(opt, false)
    86  	if v := leveldb_readoptions_get_fill_cache(opt); v != false {
    87  		t.Fatalf("expect = false, got = %v", v)
    88  	}
    89  }
    90  
    91  func TestReadOptions_leveldb_readoptions_t_convert(t *testing.T) {
    92  	var ro = &ReadOptions{}
    93  	var opt *leveldb_readoptions_t
    94  
    95  	opt = leveldb_readoptions_create_copy(ro)
    96  	if v := leveldb_readoptions_get_verify_checksums(opt); v != false {
    97  		t.Fatalf("expect = false, got = %v", v)
    98  	}
    99  	if v := leveldb_readoptions_get_fill_cache(opt); v != true {
   100  		t.Fatalf("expect = true, got = %v", v)
   101  	}
   102  	leveldb_readoptions_destroy(opt)
   103  
   104  	ro.SetFlag(RFVerifyChecksums)
   105  	opt = leveldb_readoptions_create_copy(ro)
   106  	if v := leveldb_readoptions_get_verify_checksums(opt); v != true {
   107  		t.Fatalf("expect = true, got = %v", v)
   108  	}
   109  	leveldb_readoptions_destroy(opt)
   110  
   111  	ro.SetFlag(RFDontFillCache)
   112  	opt = leveldb_readoptions_create_copy(ro)
   113  	if v := leveldb_readoptions_get_fill_cache(opt); v != false {
   114  		t.Fatalf("expect = false, got = %v", v)
   115  	}
   116  	leveldb_readoptions_destroy(opt)
   117  }
   118  
   119  func TestWriteOptions(t *testing.T) {
   120  	opt := &WriteOptions{}
   121  	if v := opt.HasFlag(WFSync); v != false {
   122  		t.Fatalf("expect = false, got = %v", v)
   123  	}
   124  	opt.SetFlag(WFSync)
   125  	if v := opt.HasFlag(WFSync); v != true {
   126  		t.Fatalf("expect = true, got = %v", v)
   127  	}
   128  	opt.ClearFlag(WFSync)
   129  	if v := opt.HasFlag(WFSync); v != false {
   130  		t.Fatalf("expect = false, got = %v", v)
   131  	}
   132  }
   133  
   134  func TestWriteOptions_leveldb_writeoptions_t(t *testing.T) {
   135  	opt := leveldb_writeoptions_create()
   136  	defer leveldb_writeoptions_destroy(opt)
   137  
   138  	if v := leveldb_writeoptions_get_sync(opt); v != false {
   139  		t.Fatalf("expect = false, got = %v", v)
   140  	}
   141  	leveldb_writeoptions_set_sync(opt, true)
   142  	if v := leveldb_writeoptions_get_sync(opt); v != true {
   143  		t.Fatalf("expect = true, got = %v", v)
   144  	}
   145  	leveldb_writeoptions_set_sync(opt, false)
   146  	if v := leveldb_writeoptions_get_sync(opt); v != false {
   147  		t.Fatalf("expect = false, got = %v", v)
   148  	}
   149  }
   150  
   151  func TestWriteOptions_leveldb_writeoptions_t_convert(t *testing.T) {
   152  	var wo = &WriteOptions{}
   153  	var opt *leveldb_writeoptions_t
   154  
   155  	opt = leveldb_writeoptions_create_copy(wo)
   156  	if v := leveldb_writeoptions_get_sync(opt); v != false {
   157  		t.Fatalf("expect = false, got = %v", v)
   158  	}
   159  	leveldb_writeoptions_destroy(opt)
   160  
   161  	opt = leveldb_writeoptions_create_copy(wo)
   162  	if v := leveldb_writeoptions_get_sync(opt); v != false {
   163  		t.Fatalf("expect = false, got = %v", v)
   164  	}
   165  	leveldb_writeoptions_destroy(opt)
   166  
   167  	wo.SetFlag(WFSync)
   168  	opt = leveldb_writeoptions_create_copy(wo)
   169  	if v := leveldb_writeoptions_get_sync(opt); v != true {
   170  		t.Fatalf("expect = true, got = %v", v)
   171  	}
   172  	leveldb_writeoptions_destroy(opt)
   173  }