code: def test_equaltoutf8andsize(self):
      # Test PyUnicode_EqualToUTF8AndSize()
      from _testcapi import (
          unicode_equaltoutf8andsize as equaltoutf8andsize,
      )
      from _testcapi import unicode_asutf8andsize as asutf8andsize
  
      strings = [
          "abc",
          "\xa1\xa2\xa3",
          "\u4f60\u597d\u4e16",
          "\U0001f600\U0001f601\U0001f602",
          "\U0010ffff",
      ]
      for s in strings:
          # Call PyUnicode_AsUTF8AndSize() which creates the UTF-8
          # encoded string cached in the Unicode object.
          asutf8andsize(s, 0)
          b = s.encode()
          self.assertEqual(
              equaltoutf8andsize(s, b), 1
          )  # Use the UTF-8 cache.
          s2 = b.decode()  # New Unicode object without the UTF-8 cache.
          self.assertEqual(equaltoutf8andsize(s2, b), 1)
          self.assertEqual(equaltoutf8andsize(s + "x", b + b"x"), 1)
          self.assertEqual(equaltoutf8andsize(s + "x", b + b"y"), 0)
          self.assertEqual(equaltoutf8andsize(s, b + b"\0"), 0)
          self.assertEqual(equaltoutf8andsize(s2, b + b"\0"), 0)
          self.assertEqual(equaltoutf8andsize(s + "\0", b + b"\0"), 1)
          self.assertEqual(equaltoutf8andsize(s + "\0", b), 0)
          self.assertEqual(equaltoutf8andsize(s2, b + b"x"), 0)
          self.assertEqual(equaltoutf8andsize(s2, b[:-1]), 0)
          self.assertEqual(equaltoutf8andsize(s2, b[:-1] + b"x"), 0)
          # Not null-terminated,
          self.assertEqual(equaltoutf8andsize(s, b + b"x", len(b)), 1)
          self.assertEqual(equaltoutf8andsize(s2, b + b"x", len(b)), 1)
          self.assertEqual(
              equaltoutf8andsize(s + "\0", b + b"\0x", len(b) + 1), 1
          )
          self.assertEqual(equaltoutf8andsize(s2, b, len(b) - 1), 0)
          self.assertEqual(equaltoutf8andsize(s, b, -1), 0)
          self.assertEqual(equaltoutf8andsize(s, b, PY_SSIZE_T_MAX), 0)
          self.assertEqual(equaltoutf8andsize(s, b, PY_SSIZE_T_MIN), 0)
  
      self.assertEqual(equaltoutf8andsize("", b""), 1)
      self.assertEqual(equaltoutf8andsize("", b"\0"), 0)
      self.assertEqual(equaltoutf8andsize("", b"x", 0), 1)
  
      # embedded null chars/bytes
      self.assertEqual(equaltoutf8andsize("abc\0def", b"abc\0def"), 1)
      self.assertEqual(
          equaltoutf8andsize("abc\0def\0", b"abc\0def\0"), 1
      )
  
      # Surrogate characters are always treated as not equal
      self.assertEqual(
          equaltoutf8andsize(
              "\udcfe", "\udcfe".encode("utf8", "surrogateescape")
          ),
          0,
      )
      self.assertEqual(
          equaltoutf8andsize(
              "\udcfe", "\udcfe".encode("utf8", "surrogatepass")
          ),
          0,
      )
      self.assertEqual(
          equaltoutf8andsize(
              "\ud801", "\ud801".encode("utf8", "surrogatepass")
          ),
          0,
      )
  
      def check_not_equal_encoding(text, encoding):
          self.assertEqual(
              equaltoutf8andsize(text, text.encode(encoding)), 0
          )
          self.assertNotEqual(
              text.encode(encoding), text.encode("utf8")
          )
  
      # Strings encoded to other encodings are not equal to expected UTF8-encoding string
      check_not_equal_encoding("Stéphane", "latin1")
      check_not_equal_encoding(
          "Stéphane", "utf-16-le"
      )  # embedded null characters
      check_not_equal_encoding("北京市", "gbk")
  
imports: import unittest
  import sys
  from test import support
  from test.support import import_helper
label_desc: Use image node_id 43 for calling the CAPITest obj's underlying member method code with example usage: obj.test_equaltoutf8andsize() without return types