Best Syzkaller code snippet using report.isCorrupted
reader_test.go
Source:reader_test.go
1// Copyright 2015, Joe Tsai. All rights reserved.2// Use of this source code is governed by a BSD-style3// license that can be found in the LICENSE.md file.4package xflate5import (6 "bytes"7 "io"8 "io/ioutil"9 "math"10 "math/rand"11 "testing"12 "github.com/itchio/dskompress/internal/errors"13 "github.com/itchio/dskompress/internal/testutil"14)15type countReadSeeker struct {16 io.ReadSeeker17 N int6418}19func (rs *countReadSeeker) Read(buf []byte) (int, error) {20 n, err := rs.ReadSeeker.Read(buf)21 rs.N += int64(n)22 return n, err23}24func TestReader(t *testing.T) {25 dh := testutil.MustDecodeHex26 errFuncs := map[string]func(error) bool{27 "IsCorrupted": errors.IsCorrupted,28 }29 vectors := []struct {30 desc string // Description of the test31 input []byte // Input test string32 output []byte // Expected output string33 errf string // Name of error checking callback34 }{{35 desc: "empty string",36 errf: "IsCorrupted",37 }, {38 desc: "empty stream",39 input: dh("" +40 "0d008705000048c82a51e8ff37dbf1",41 ),42 }, {43 desc: "empty stream with empty chunk",44 input: dh("" +45 "000000ffff000000ffff34c086050020916cb2a50bd20369da192deaff3bda05" +46 "f81dc08605002021ab44219b4aff7fd6de3bf8",47 ),48 }, {49 desc: "empty stream with empty index",50 input: dh("" +51 "04c086050020191d53a1a508c9e8ff5bda7bf815c08605002021ab44219ba2ff" +52 "2f6bef5df8",53 ),54 }, {55 desc: "empty stream with multiple empty chunks",56 input: dh("" +57 "000000ffff000000ffff000000ffff148086058044655366e3817441ba205d50" +58 "4a83348c445ddcde7b6ffc15c08605002021ab44a103aaff2f6bef5df8",59 ),60 }, {61 desc: "empty stream with multiple empty chunks, with final bit",62 input: dh("" +63 "000000ffff010000ffff000000ffff148086058044655366e3817441ba205d50" +64 "4a83348c445ddcde7b6ffc15c08605002021ab44a103aaff2f6bef5df8",65 ),66 errf: "IsCorrupted",67 }, {68 desc: "empty stream with multiple empty indexes",69 input: dh("" +70 "04c086050020191d53a1a508c9e8ff5bda7bf83cc08605002019293a24a55464" +71 "a585faff9bf600f804c08605002019493a2494d050560afd7f4c7bfb25008705" +72 "000048c82a51e880f4ff834df0",73 ),74 }, {75 desc: "3k zeros, 1KiB chunks",76 input: dh("" +77 "621805a360148c5800000000ffff621805a360148c5800000000ffff621805a3" +78 "60140c3900000000ffff1c8086058044642b3bc9aa3464540784acea809055d9" +79 "9586dd5492446555a7b607fc0d008705000048c82a51c81ea1ff0f6cf2",80 ),81 output: make([]byte, 3000),82 }, {83 desc: "quick brown fox - spec example",84 input: dh("" +85 "0ac94855282ccd4cce560028a928bf3c4f212dbf4201a0acd2dc82d41485fcb2" +86 "d42205804a80f2398955950a00000000ffff4ac94f5704000000ffff24808605" +87 "8084b247b60629218a48486656d2b442ca489fb7f7de0bfc3cc08605002019a1" +88 "3aa454548a122ad5fff7b403f815c08605002021ab44219ba4ff2f6bef5df8",89 ),90 output: []byte("The quick brown fox jumped over the lazy dog!"),91 }, {92 desc: "quick brown fox - manual chunking/indexing",93 input: dh("" +94 "2ac94855282ccd4cce06000000ffff52482aca2fcf5348cbaf00000000ffff00" +95 "0000ffff52c82acd2d484d51c82f4b2d5228c94805000000ffff248086058044" +96 "6553762a0ad14211d207253b234546a1528ad4d3edbd0bfc52c849acaa5448c9" +97 "4f07000000ffff2c8086058044a281ec8611190d23b21221ca0851fdafbdf7de" +98 "05fc1dc08605002021ab44219b52ff7fd6de3bf8",99 ),100 output: []byte("the quick brown fox jumped over the lazy dog"),101 }, {102 desc: "quick brown fox - automatic chunking/indexing",103 input: dh("" +104 "2ac9485500000000ffff2a2ccd4c06000000ffffca56482a02000000ffff2c80" +105 "86058044655376c32a2b9999c9cc4c665691d04ea5a474747bef01fcca2fcf53" +106 "00000000ffff4acbaf5000000000ffffca2acd2d00000000ffff048086058044" +107 "45036537acb2929999cccc6466cb48112a45a193db7beffc4a4d51c807000000" +108 "ffff2a4b2d5200000000ffff2ac9485500000000ffff04808605804445036537" +109 "acb2929999cccc6466cb48112a45a193db7beffcca49acaa04000000ffff5248" +110 "c94f07000000ffff148086058084a261644b665632339399d9425629a44877b7" +111 "f7de3bfc15c08605002021ab44a103aaff2f6bef5df8",112 ),113 output: []byte("the quick brown fox jumped over the lazy dog"),114 }, {115 desc: "alphabet",116 input: dh("" +117 "4a4c4a4e494d4bcfc8cccacec9cdcb2f282c2a2e292d2bafa8ac02000000ffff" +118 "048086058044b2e98190b285148a844a0b95a4f7db7bef3dfc15c08605002021" +119 "ab44219ba8ff2f6bef5df8",120 ),121 output: []byte("abcdefghijklmnopqrstuvwxyz"),122 }, {123 desc: "garbage footer",124 input: dh("5174453181b67484bf6de23a608876f8b7f44c77"),125 errf: "IsCorrupted",126 }, {127 desc: "corrupt meta footer",128 input: dh("1d008705000048ca2c50e8ff3bdbf0"),129 errf: "IsCorrupted",130 }, {131 desc: "trailing meta data in footer",132 input: dh("0d008705000048c82a51e8ff37dbf1deadcafe"),133 errf: "IsCorrupted",134 }, {135 desc: "trailing raw data in footer",136 input: dh("25c086050020a9ac12856ec8284229d4ff0fb527f8"),137 errf: "IsCorrupted",138 }, {139 desc: "footer using LastMeta",140 input: dh("0c008705000048c82a51e8ff37dbf1"),141 errf: "IsCorrupted",142 }, {143 desc: "footer without magic",144 input: dh("1d00870500004864a644eaff3bdbf0"),145 errf: "IsCorrupted",146 }, {147 desc: "footer with VLI overflow",148 input: dh("2d80860580944a458a4abb6e6c9fdbde7bef01fc"),149 errf: "IsCorrupted",150 }, {151 desc: "index using LastStream",152 input: dh("" +153 "05c086050020191d53a1a508c9e8ff5bda7bf815c08605002021ab44219ba2ff" +154 "2f6bef5df8",155 ),156 errf: "IsCorrupted",157 }, {158 desc: "index with wrong CRC",159 input: dh("" +160 "2cc086050020191d132551320a51ff9fd2de0bf825008705000048c82a51e880" +161 "f4ff834df0",162 ),163 errf: "IsCorrupted",164 }, {165 desc: "corrupt meta index",166 input: dh("" +167 "04c086050020191d53a1a518c9e8ff5bda7bf815c08605002021ab44219ba2ff" +168 "2f6bef5df8",169 ),170 errf: "IsCorrupted",171 }, {172 desc: "index with VLI overflow",173 input: dh("" +174 "048086058094e8c6f6de7b531215458a840e6deffc15c08605002021ab44219b" +175 "a4ff2f6bef5df8",176 ),177 errf: "IsCorrupted",178 }, {179 desc: "trailing meta data in index",180 input: dh("" +181 "34c086050020291d53a1a508c908a16414a2fe3fa205f81dc08605002021ab44" +182 "219b4aff7fd6de3bf8",183 ),184 errf: "IsCorrupted",185 }, {186 desc: "trailing raw data in index",187 input: dh("" +188 "04c086050020191d53a1a508c9e8ff5bda7bf862616405c08605002021ab4421" +189 "7b94febfacbd77f9",190 ),191 errf: "IsCorrupted",192 }, {193 desc: "index total size is wrong",194 input: dh("" +195 "000000ffff14c086050020916cb2d505e983840aa12592faff8c76f81dc08605" +196 "002021ab44219b4aff7fd6de3bf8",197 ),198 errf: "IsCorrupted",199 }, {200 desc: "index with compressed chunk size of zero",201 input: dh("" +202 "000000ffff04c086050020916cb2e9848e8894a2a441fd7f457bf905c0860500" +203 "2021ab44217b94febfacbd77f9",204 ),205 errf: "IsCorrupted",206 }, {207 desc: "index with numeric overflow on sizes",208 input: dh("" +209 "000000ffff000000ffff0c40860552a43db4a53dcf6b97b47724641589a84e69" +210 "efbdf7de7b4ffe1dc08605002021ab44219b54ff7fd6de3bf8",211 ),212 errf: "IsCorrupted",213 }, {214 desc: "empty chunk without sync marker",215 input: dh("" +216 "000000ffff020820800004c086050020a1ec919d1e4817a40b421269a3a8ff1f" +217 "68fa2d008705000048c82a51e881faffc126f0",218 ),219 errf: "IsCorrupted",220 }, {221 desc: "chunk without sync marker",222 input: dh("" +223 "000000ffff000200fdff486902082080000cc086050020a1ec91193232d30965" +224 "652b2b221125f5ff1eedf805c08605002021ab44217ba4febfacbd77f9",225 ),226 output: []byte("Hi"),227 errf: "IsCorrupted",228 }, {229 desc: "chunk with wrong sizes",230 input: dh("" +231 "000000ffff000200fdff4869000000ffff2c8086058084b2476608d9e98432b2" +232 "15252a958a92eaeef6de7b07fc15c08605002021ab44a103aaff2f6bef5df8",233 ),234 output: []byte("Hi"),235 errf: "IsCorrupted",236 }, {237 desc: "size overflow across multiple indexes",238 input: dh("" +239 "000000ffff0c8086058094b487b6b4ce4b5ae7150d49d124195dd29efc000000" +240 "ffff000000ffff24808605808432cac84e4676ba2059d9914a4a29259a8fb7f7" +241 "de0bfc15c08605002021ab44a103aaff2f6bef5df8",242 ),243 errf: "IsCorrupted",244 }, {245 desc: "index back size causes integer overflow",246 input: dh("" +247 "4a4c4a4e494d4bcfc8cccacec9cdcb2f282c2a2e292d2bafa8ac02000000ffff" +248 "048086058044b2e98190b285148a844a0b95a4f7db7bef3dfc4a4c4a4e494d4b" +249 "cfc8cccacec9cdcb2f282c2a2e292d2bafa8ac02000000ffff2c8086058094e8" +250 "bcb4a74ab4538986529284cc3e6def05fc2d008705000048c82a51e881faffc1" +251 "26f0"),252 errf: "IsCorrupted",253 }, {254 desc: "raw chunk with final bit and bad size",255 input: dh("" +256 "010900f6ff0000ffff248086058044b2c98e8cc8888cc828ed9d284afa7fb4f7" +257 "de0bfc05c08605002021ab44217ba4febfacbd77f9",258 ),259 output: dh("0000ffff010000ffff"),260 // TODO(dsnet): The Reader incorrectly believes that this is valid.261 // The chunk has a final raw block with a specified size of 9, but only262 // has 4 bytes following it (0000ffff to fool the sync check).263 // Since the decompressor would expect an additional 5 bytes, this is264 // satisfied by the fact that the chunkReader appends the endBlock265 // sequence (010000ffff) to every chunk. This really difficult to fix266 // without low-level details about the DEFLATE stream.267 errf: "", // "IsCorrupted",268 }}269 for i, v := range vectors {270 var xr *Reader271 var err error272 var buf []byte273 xr, err = NewReader(bytes.NewReader(v.input), nil)274 if err != nil {275 goto done276 }277 buf, err = ioutil.ReadAll(xr)278 if err != nil {279 goto done280 }281 done:282 if v.errf != "" && !errFuncs[v.errf](err) {283 t.Errorf("test %d (%s), mismatching error:\ngot %v\nwant %s(err) == true", i, v.desc, err, v.errf)284 } else if v.errf == "" && err != nil {285 t.Errorf("test %d (%s), unexpected error: got %v", i, v.desc, err)286 }287 if got, want, ok := testutil.BytesCompare(buf, v.output); !ok && err == nil {288 t.Errorf("test %d (%s), mismatching output:\ngot %s\nwant %s", i, v.desc, got, want)289 }290 }291}292func TestReaderReset(t *testing.T) {293 var (294 empty = testutil.MustDecodeHex("0d008705000048c82a51e8ff37dbf1")295 badSize = testutil.MustDecodeHex("" +296 "4a4c4a4e494d4bcfc8cccacec9cdcb2f282c2a2e292d2bafa8ac02000000ffff" +297 "3c8086058084b2e981acd0203b2b34884a834a2a91d2ededbd7701fc15c08605" +298 "002021ab44a103aaff2f6bef5df8",299 )300 badData = testutil.MustDecodeHex("" +301 "4a4c4a4e494d4bcfc8cccacec9cdcb2f282c2a2e292d2baf000002000000ffff" +302 "048086058044b2e98190b285148a844a0b95a4f7db7bef3dfc15c08605002021" +303 "ab44219ba8ff2f6bef5df8",304 )305 )306 // Test Reader for idempotent Close.307 xr := new(Reader)308 if err := xr.Reset(bytes.NewReader(empty)); err != nil {309 t.Fatalf("unexpected error: Reset() = %v", err)310 }311 buf, err := ioutil.ReadAll(xr)312 if err != nil {313 t.Fatalf("unexpected error: ReadAll() = %v", err)314 }315 if len(buf) > 0 {316 t.Fatalf("unexpected output data: ReadAll() = %q, want nil", buf)317 }318 if err := xr.Close(); err != nil {319 t.Fatalf("unexpected error: Close() = %v", err)320 }321 if err := xr.Close(); err != nil {322 t.Fatalf("unexpected error: Close() = %v", err)323 }324 if _, err := ioutil.ReadAll(xr); err != errClosed {325 t.Fatalf("mismatching error: ReadAll() = %v, want %v", err, errClosed)326 }327 // Test Reset on garbage data.328 rd := bytes.NewReader(append([]byte("garbage"), empty...))329 if err := xr.Reset(rd); !errors.IsCorrupted(err) {330 t.Fatalf("mismatching error: Reset() = %v, want IsCorrupted(err) == true", err)331 }332 if _, err := xr.Seek(0, io.SeekStart); !errors.IsCorrupted(err) {333 t.Fatalf("mismatching error: Seek() = %v, want IsCorrupted(err) == true", err)334 }335 if err := xr.Close(); !errors.IsCorrupted(err) {336 t.Fatalf("mismatching error: Close() = %v, want IsCorrupted(err) == true", err)337 }338 // Test Reset on corrupt data in discard section.339 for i, v := range [][]byte{badData, badSize} {340 if err := xr.Reset(bytes.NewReader(v)); err != nil {341 t.Fatalf("test %d, unexpected error: Reset() = %v", i, err)342 }343 if _, err := xr.Seek(-1, io.SeekEnd); err != nil {344 t.Fatalf("test %d, unexpected error: Seek() = %v", i, err)345 }346 if _, err = ioutil.ReadAll(xr); !errors.IsCorrupted(err) {347 t.Fatalf("test %d, mismatching error: ReadAll() = %v, want IsCorrupted(err) == true", i, err)348 }349 }350}351func TestReaderSeek(t *testing.T) {352 rand := rand.New(rand.NewSource(0))353 twain := testutil.MustLoadFile("../testdata/twain.txt")354 // Generate compressed version of input file.355 var buf bytes.Buffer356 xw, err := NewWriter(&buf, &WriterConfig{ChunkSize: 1 << 10})357 if err != nil {358 t.Fatalf("unexpected error: NewWriter() = %v", err)359 }360 if _, err := xw.Write(twain); err != nil {361 t.Fatalf("unexpected error: Write() = %v", err)362 }363 if err := xw.Close(); err != nil {364 t.Fatalf("unexpected error: Close() = %v", err)365 }366 // Read the compressed file.367 rs := &countReadSeeker{ReadSeeker: bytes.NewReader(buf.Bytes())}368 xr, err := NewReader(rs, nil)369 if err != nil {370 t.Fatalf("unexpected error: NewReader() = %v", err)371 }372 // As a heuristic, make sure we are not reading too much data.373 if thres := int64(len(twain) / 100); rs.N > thres {374 t.Fatalf("read more data than expected: %d > %d", rs.N, thres)375 }376 rs.N = 0 // Reset the read count377 // Generate list of seek commands to try.378 type seekCommand struct {379 length int // Number of bytes to read380 offset int64 // Seek to this offset381 whence int // Whence value to use382 }383 vectors := []seekCommand{384 {length: 40, offset: int64(len(twain)) - 1, whence: io.SeekStart},385 {length: 40, offset: int64(len(twain)), whence: io.SeekStart},386 {length: 40, offset: int64(len(twain)) + 1, whence: io.SeekStart},387 {length: 40, offset: math.MaxInt64, whence: io.SeekStart},388 {length: 0, offset: 0, whence: io.SeekCurrent},389 {length: 13, offset: 15, whence: io.SeekStart},390 {length: 32, offset: 23, whence: io.SeekCurrent},391 {length: 32, offset: -23, whence: io.SeekCurrent},392 {length: 13, offset: -15, whence: io.SeekStart},393 {length: 100, offset: -15, whence: io.SeekEnd},394 {length: 0, offset: 0, whence: io.SeekCurrent},395 {length: 0, offset: 0, whence: io.SeekCurrent},396 {length: 32, offset: -34, whence: io.SeekCurrent},397 {length: 32, offset: -34, whence: io.SeekCurrent},398 {length: 2000, offset: 53, whence: io.SeekStart},399 {length: 2000, offset: int64(len(twain)) - 1000, whence: io.SeekStart},400 {length: 0, offset: 0, whence: io.SeekCurrent},401 {length: 100, offset: -int64(len(twain)), whence: io.SeekEnd},402 {length: 100, offset: -int64(len(twain)) - 1, whence: io.SeekEnd},403 {length: 0, offset: 0, whence: io.SeekStart},404 {length: 10, offset: 10, whence: io.SeekCurrent},405 {length: 10, offset: 10, whence: io.SeekCurrent},406 {length: 10, offset: 10, whence: io.SeekCurrent},407 {length: 10, offset: 10, whence: io.SeekCurrent},408 {length: 0, offset: 0, whence: -1},409 }410 // Add random values to seek list.411 for i := 0; i < 100; i++ {412 length, offset := rand.Intn(1<<11), rand.Int63n(int64(len(twain)))413 if length+int(offset) <= len(twain) {414 vectors = append(vectors, seekCommand{length, offset, io.SeekStart})415 }416 }417 // Read in reverse.418 vectors = append(vectors, seekCommand{0, 0, io.SeekEnd})419 for pos := int64(len(twain)); pos > 0; {420 n := int64(rand.Intn(1 << 11))421 if n > pos {422 n = pos423 }424 pos -= n425 vectors = append(vectors, seekCommand{int(n), pos, io.SeekStart})426 }427 // Execute all seek commands.428 var pos, totalLength int64429 for i, v := range vectors {430 // Emulate Seek logic.431 var wantPos int64432 switch v.whence {433 case io.SeekStart:434 wantPos = v.offset435 case io.SeekCurrent:436 wantPos = v.offset + pos437 case io.SeekEnd:438 wantPos = v.offset + int64(len(twain))439 default:440 wantPos = -1441 }442 // Perform actually (short-circuit if seek fails).443 wantFail := bool(wantPos < 0)444 gotPos, err := xr.Seek(v.offset, v.whence)445 if gotFail := bool(err != nil); gotFail != wantFail {446 if gotFail {447 t.Fatalf("test %d, unexpected failure: Seek(%d, %d) = (%d, %v)", i, v.offset, v.whence, pos, err)448 } else {449 t.Fatalf("test %d, unexpected success: Seek(%d, %d) = (%d, nil)", i, v.offset, v.whence, pos)450 }451 }452 if wantFail {453 continue454 }455 if gotPos != wantPos {456 t.Fatalf("test %d, offset mismatch: got %d, want %d", i, gotPos, wantPos)457 }458 // Read and verify some length of bytes.459 var want []byte460 if wantPos < int64(len(twain)) {461 want = twain[wantPos:]462 }463 if len(want) > v.length {464 want = want[:v.length]465 }466 got, err := ioutil.ReadAll(io.LimitReader(xr, int64(v.length)))467 if err != nil {468 t.Fatalf("test %v, unexpected error: ReadAll() = %v", i, err)469 }470 if got, want, ok := testutil.BytesCompare(got, want); !ok {471 t.Fatalf("test %v, mismatching output:\ngot %s\nwant %s", i, got, want)472 }473 pos = gotPos + int64(len(got))474 totalLength += int64(v.length)475 }476 // As a heuristic, make sure we are not reading too much data.477 if thres := 2 * totalLength; rs.N > thres {478 t.Fatalf("read more data than expected: %d > %d", rs.N, thres)479 }480}481func TestRecursiveReader(t *testing.T) {482 twain := testutil.MustLoadFile("../testdata/twain.txt")483 const numIters = 5484 var bb bytes.Buffer485 // Recursively compress the same input data multiple times using XFLATE.486 // Run as a closured function to ensure defer statements execute.487 func() {488 wlast := io.Writer(&bb) // Latest writer489 for i := 0; i < numIters; i++ {490 xw, err := NewWriter(wlast, &WriterConfig{ChunkSize: 1 << uint(10+i)})491 if err != nil {492 t.Fatalf("unexpected error: NewWriter() = %v", err)493 }494 defer func() {495 if err := xw.Close(); err != nil {496 t.Fatalf("unexpected error: Close() = %v", err)497 }498 }()499 wlast = xw500 }501 if _, err := wlast.Write(twain); err != nil {502 t.Fatalf("unexpected error: Write() = %v", err)503 }504 }()505 // Recursively decompress the same input stream multiple times.506 func() {507 rlast := io.ReadSeeker(bytes.NewReader(bb.Bytes()))508 for i := 0; i < numIters; i++ {509 xr, err := NewReader(rlast, nil)510 if err != nil {511 t.Fatalf("unexpected error: NewReader() = %v", err)512 }513 defer func() {514 if err := xr.Close(); err != nil {515 t.Fatalf("unexpected error: Close() = %v", err)516 }517 }()518 rlast = xr519 }520 buf := make([]byte, 321)521 if _, err := rlast.Seek(int64(len(twain))/2, io.SeekStart); err != nil {522 t.Fatalf("unexpected error: Seek() = %v", err)523 }524 if _, err := io.ReadFull(rlast, buf); err != nil {525 t.Fatalf("unexpected error: Read() = %v", err)526 }527 if got, want := string(buf), string(twain[len(twain)/2:][:321]); got != want {528 t.Errorf("output mismatch:\ngot %q\nwant %q", got, want)529 }530 }()531}532// BenchmarkReader benchmarks the overhead of the XFLATE format over DEFLATE.533// Thus, it intentionally uses a very small chunk size with no compression.534// This benchmark reads the input file in reverse to excite poor behavior.535func BenchmarkReader(b *testing.B) {536 rand := rand.New(rand.NewSource(0))537 twain := testutil.MustLoadFile("../testdata/twain.txt")538 bb := bytes.NewBuffer(make([]byte, 0, 2*len(twain)))539 xr := new(Reader)540 lr := new(io.LimitedReader)541 xw, _ := NewWriter(bb, &WriterConfig{Level: NoCompression, ChunkSize: 1 << 10})542 xw.Write(twain)543 xw.Close()544 b.ReportAllocs()545 b.SetBytes(int64(len(twain)))546 b.ResetTimer()547 for i := 0; i < b.N; i++ {548 rand.Seed(0)549 rd := bytes.NewReader(bb.Bytes())550 if err := xr.Reset(rd); err != nil {551 b.Fatalf("unexpected error: Reset() = %v", err)552 }553 // Read sections of the input in reverse.554 for pos := int64(len(twain)); pos > 0; {555 // Random section size.556 n := int64(rand.Intn(1 << 11))557 if n > pos {558 n = pos559 }560 pos -= n561 // Read the given section.562 if _, err := xr.Seek(pos, io.SeekStart); err != nil {563 b.Fatalf("unexpected error: Seek() = %v", err)564 }565 *lr = io.LimitedReader{R: xr, N: n}566 if _, err := io.Copy(ioutil.Discard, lr); err != nil {567 b.Fatalf("unexpected error: Copy() = %v", err)568 }569 }570 }571}...
isCorrupted
Using AI Code Generation
1import (2func main() {3 file, err := excelize.OpenFile("test.xlsx")4 if err != nil {5 fmt.Println(err)6 }7 cell, err := file.GetCellValue("Sheet1", "B2")8 if err != nil {9 fmt.Println(err)10 }11 fmt.Println(cell)12 rows, err := file.GetRows("Sheet1")13 for _, row := range rows {14 for _, colCell := range row {15 fmt.Print(colCell, "\t")16 }17 fmt.Println()18 }19}20github.com/360EntSecGroup-Skylar/excelize.(*File).GetCellValue(0x0, 0x5a2c2d, 0x6, 0x5a2c2d, 0x6, 0x0)21main.main()22import (23func main() {24 file, err := excelize.OpenFile("test.xlsx")25 if err != nil {26 fmt.Println(err)27 }28 cell, err := file.GetCellValue("Sheet1", "B2")29 if err != nil {30 fmt.Println(err)31 }32 fmt.Println(cell)33}
isCorrupted
Using AI Code Generation
1import (2type report struct {3}4type temperature struct {5}6type location struct {7}8func (t temperature) average() celsius {9 return (t.high + t.low) / 210}11func (r report) average() celsius {12 return r.temperature.average()13}14func (r report) isCorrupted() bool {15 if r.temperature.high < r.temperature.low {16 }17}18func main() {19 report := report{20 temperature: temperature{21 },22 location: location{23 },24 }25 fmt.Println(report)26 fmt.Println(report.average())27 fmt.Println(report.isCorrupted())28}29{15 {-1 -78} {4.5 135.9}}
isCorrupted
Using AI Code Generation
1import "fmt"2type report struct {3}4func (r *report) isCorrupted() bool {5 for i := 0; i < 5; i++ {6 for j := 0; j < 5; j++ {7 if r.grid[i][j] != '.' && r.grid[i][j] != '#' {8 }9 }10 }11}12func main() {13 fmt.Println(r.isCorrupted())14}15import "fmt"16type report struct {17}18func (r *report) isCorrupted() bool {19 for i := 0; i < 5; i++ {20 for j := 0; j < 5; j++ {21 if r.grid[i][j] != '.' && r.grid[i][j] != '#' {22 }23 }24 }25}26func main() {27 fmt.Println(r.isCorrupted())28}29import "fmt"30type report struct {31}32func (r *report) isCorrupted() bool {33 for i := 0; i < 5; i++ {34 for j := 0; j < 5; j++ {35 if r.grid[i][j] != '.' && r.grid[i][j] != '#' {36 }37 }38 }39}40func main() {41 fmt.Println(r.isCorrupted())42}43import "fmt"44type report struct {45}46func (r *
isCorrupted
Using AI Code Generation
1import (2func main() {3 fmt.Println(report.IsCorrupted())4}5./2.go:10: cannot use report (type xlsx.Report) as type xlsx.File in argument to xlsx.IsCorrupted:6 xlsx.Report does not implement xlsx.File (missing GetSheet method)
isCorrupted
Using AI Code Generation
1import (2func main() {3 r := new(Report)4 f, err := os.Create("report1.txt")5 if err != nil {6 log.Fatal(err)7 }8 r.Created = time.Now()9 fmt.Println(r.isCorrupted())10}11import (12func main() {13 r := new(Report)14 f, err := os.Create("report1.txt")15 if err != nil {16 log.Fatal(err)17 }18 r.Created = time.Now()19 fmt.Println(r.isCorrupted())20}21import (22func main() {23 r := new(Report)24 f, err := os.Create("report1.txt")25 if err != nil {26 log.Fatal(err)27 }28 r.Created = time.Now()29 fmt.Println(r.isCorrupted())30}31import (32func main() {33 r := new(Report)
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!