mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-06 01:05:48 +02:00
Add tests for the xxhash based hashers
This commit is contained in:
@@ -290,6 +290,13 @@ digest(Hasher *self, PyObject *args UNUSED) {
|
||||
return ans;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
digest64(Hasher *self, PyObject *args UNUSED) {
|
||||
if (self->h.digest64 == NULL) { PyErr_SetString(PyExc_TypeError, "Does not support 64-bit digests"); return NULL; }
|
||||
unsigned long long a = self->h.digest64(self->h.state);
|
||||
return PyLong_FromUnsignedLongLong(a);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
hexdigest(Hasher *self, PyObject *args UNUSED) {
|
||||
uint8_t digest[64]; char hexdigest[128];
|
||||
@@ -314,6 +321,7 @@ Hasher_name(Hasher* self, void* closure UNUSED) { return PyUnicode_FromString(se
|
||||
static PyMethodDef Hasher_methods[] = {
|
||||
METHODB(update, METH_O),
|
||||
METHODB(digest, METH_NOARGS),
|
||||
METHODB(digest64, METH_NOARGS),
|
||||
METHODB(hexdigest, METH_NOARGS),
|
||||
METHODB(reset, METH_NOARGS),
|
||||
{NULL} /* Sentinel */
|
||||
|
||||
@@ -11,7 +11,7 @@ from pathlib import Path
|
||||
|
||||
from kittens.transfer.main import parse_transfer_args
|
||||
from kittens.transfer.receive import File, files_for_receive
|
||||
from kittens.transfer.rsync import decode_utf8_buffer, parse_ftc
|
||||
from kittens.transfer.rsync import decode_utf8_buffer, parse_ftc, Hasher
|
||||
from kittens.transfer.utils import cwd_path, expand_home, home_path, set_paths
|
||||
from kitty.file_transmission import Action, Compression, FileTransmissionCommand, FileType, TransmissionType, ZlibDecompressor, iter_file_metadata
|
||||
from kitty.file_transmission import TestFileTransmission as FileTransmission
|
||||
@@ -425,3 +425,12 @@ class TestFileTransmission(BaseTest):
|
||||
self.assertEqual(files[1].remote_target, files[2].remote_id)
|
||||
self.assertEqual(files[3].ftype, FileType.link)
|
||||
self.assertEqual(files[3].remote_target, files[2].remote_id)
|
||||
|
||||
def test_rsync_hashers(self):
|
||||
h = Hasher("xxh3-64")
|
||||
h.update(b'abcd')
|
||||
self.assertEqual(h.hexdigest(), '6497a96f53a89890')
|
||||
self.assertEqual(h.digest64(), 7248448420886124688)
|
||||
h128 = Hasher("xxh3-128")
|
||||
h128.update(b'abcd')
|
||||
self.assertEqual(h128.hexdigest(), '8d6b60383dfa90c21be79eecd1b1353d')
|
||||
|
||||
@@ -4,6 +4,7 @@ package rsync
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@@ -176,5 +177,20 @@ func TestRsyncRoundtrip(t *testing.T) {
|
||||
run_roundtrip_test(t, src_data, changed, num_of_patches, total_patch_size)
|
||||
run_roundtrip_test(t, src_data, changed[:len(changed)-3], num_of_patches, total_patch_size)
|
||||
run_roundtrip_test(t, src_data, append(changed, "xyz..."...), num_of_patches, total_patch_size)
|
||||
|
||||
}
|
||||
|
||||
func TestRsyncHashers(t *testing.T) {
|
||||
h := new_xxh3_64()
|
||||
h.Write([]byte("abcd"))
|
||||
if diff := cmp.Diff(hex.EncodeToString(h.Sum(nil)), `6497a96f53a89890`); diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
if diff := cmp.Diff(h.Sum64(), uint64(7248448420886124688)); diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
h2 := new_xxh3_128()
|
||||
h2.Write([]byte("abcd"))
|
||||
if diff := cmp.Diff(hex.EncodeToString(h2.Sum(nil)), `8d6b60383dfa90c21be79eecd1b1353d`); diff != "" {
|
||||
t.Fatalf(diff)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user